generated from idealjs/mono-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,339 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Tabs from "@/components/MarkdownTabs"; | ||
import TabItem from "@/components/MarkdownTabs/TabItem"; | ||
|
||
# Install camphora-styled | ||
|
||
<Tabs defaultValue="npm"> | ||
<TabItem value="npm" label="NPM"> | ||
npm i -D camphora-styled@latest | ||
</TabItem> | ||
<TabItem value="yarn" label="YARN"> | ||
yarn add -D camphora-styled@latest | ||
</TabItem> | ||
</Tabs> | ||
|
||
# camphora-styled Example Repositories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { tab, tabPanel } from "@idealjs/camphora-styled"; | ||
import clsx from "clsx"; | ||
import React, { Fragment, PropsWithChildren } from "react"; | ||
|
||
import { getDefaultValue, getGroupName } from "./context"; | ||
|
||
interface IProps { | ||
label?: string; | ||
value: string; | ||
} | ||
|
||
const TabItem = (props: PropsWithChildren<IProps>) => { | ||
const { children, value, label } = props; | ||
const groupName = getGroupName(); | ||
const defaultValue = getDefaultValue(); | ||
|
||
return ( | ||
<Fragment> | ||
<input | ||
className={clsx(tab)} | ||
type="radio" | ||
name={groupName} | ||
defaultChecked={value == defaultValue} | ||
aria-label={label ?? value} | ||
/> | ||
<div className={clsx(tabPanel)}>{children}</div> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export default TabItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import serverContext, { | ||
getServerContext, | ||
setServerContext, | ||
} from "../utils/serverContext"; | ||
|
||
const groupNameContext = serverContext<string | null>(null); | ||
|
||
export const getGroupName = () => { | ||
const value = getServerContext(groupNameContext); | ||
if (value == null) { | ||
throw new Error("context not initialized"); | ||
} | ||
return value; | ||
}; | ||
|
||
export const setGroupName = (value: string) => { | ||
setServerContext(groupNameContext, value); | ||
}; | ||
|
||
const defaultValueContext = serverContext<string | null>(null); | ||
|
||
export const getDefaultValue = () => { | ||
const value = getServerContext(defaultValueContext); | ||
return value; | ||
}; | ||
|
||
export const setDefaultValue = (value: string) => { | ||
setServerContext(defaultValueContext, value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { paper, paperSecondary, tabs } from "@idealjs/camphora-styled"; | ||
import clsx from "clsx"; | ||
import { nanoid } from "nanoid"; | ||
import React, { PropsWithChildren } from "react"; | ||
|
||
import { setDefaultValue, setGroupName } from "./context"; | ||
|
||
interface IProps { | ||
defaultValue?: string; | ||
groupName?: string; | ||
} | ||
|
||
const Tabs = (props: PropsWithChildren<IProps>) => { | ||
const { children, groupName, defaultValue } = props; | ||
setGroupName(groupName ?? nanoid()); | ||
defaultValue != null && setDefaultValue(defaultValue); | ||
|
||
return <div className={clsx(tabs, paper, paperSecondary)}>{children}</div>; | ||
}; | ||
|
||
export default Tabs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import "server-only"; | ||
|
||
import { cache } from "react"; | ||
|
||
const serverContext = <T>(defaultValue: T) => { | ||
const context = cache(() => ({ current: defaultValue })); | ||
return context; | ||
}; | ||
|
||
export default serverContext; | ||
|
||
export const getServerContext = <T>( | ||
context: () => { | ||
current: T; | ||
} | ||
) => { | ||
return context().current; | ||
}; | ||
|
||
export const setServerContext = <T>( | ||
context: () => { | ||
current: T; | ||
}, | ||
value: T | ||
) => { | ||
context().current = value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { MDXComponents } from "mdx/types"; | ||
|
||
export function useMDXComponents(components: MDXComponents): MDXComponents { | ||
return { | ||
...components, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
const { createVanillaExtractPlugin } = require("@vanilla-extract/next-plugin"); | ||
const withVanillaExtract = createVanillaExtractPlugin(); | ||
const createMDXPlugin = require("@next/mdx"); | ||
const { version } = require("./package.json"); | ||
|
||
const withMDX = createMDXPlugin(); | ||
const withVanillaExtract = createVanillaExtractPlugin(); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"], | ||
publicRuntimeConfig: { | ||
version, | ||
}, | ||
}; | ||
|
||
module.exports = withVanillaExtract(nextConfig); | ||
module.exports = withVanillaExtract(withMDX(nextConfig)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { style } from "@vanilla-extract/css"; | ||
|
||
import { vars } from "./themes"; | ||
|
||
export const tabs = style({ | ||
display: "grid", | ||
vars: {}, | ||
selectors: {}, | ||
}); | ||
|
||
export const tab = style({ | ||
selectors: { | ||
[`${tabs} &`]: { | ||
appearance: "none", | ||
gridRowStart: 1, | ||
margin: "0px", | ||
backgroundColor: vars.colors.primary.bg, | ||
color: vars.colors.primary.content, | ||
}, | ||
[`${tabs} &:checked`]: { | ||
backgroundColor: vars.colors.primary.focus, | ||
}, | ||
["&:after"]: { | ||
content: "attr(aria-label)", | ||
}, | ||
}, | ||
}); | ||
|
||
export const tabPanel = style({ | ||
selectors: { | ||
[`${tabs} &`]: { | ||
gridColumnStart: 1, | ||
gridRowStart: 2, | ||
gridColumnEnd: "span 9999", | ||
display: "none", | ||
}, | ||
[`${tab}:checked+&`]: { | ||
display: "block", | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.