diff --git a/docs/src/components/NavList.tsx b/docs/src/components/NavList.tsx index 5dccf6f8c..056bc9b05 100644 --- a/docs/src/components/NavList.tsx +++ b/docs/src/components/NavList.tsx @@ -161,6 +161,20 @@ const themeList: ListItem[] = [ href: '/@charcoal-ui/theme/colors', }, ] +const tailwindConfigList: ListItem[] = [ + { + text: 'クイックスタート', + href: '/@charcoal-ui/tailwind-config/quickstart', + }, + { + text: 'カスタマイズする', + href: '/@charcoal-ui/tailwind-config/customize', + }, + { + text: 'Typography', + href: '/@charcoal-ui/tailwind-config/typography', + }, +] export const NavList: FC<{ className?: string }> = (props) => { const router = useRouter() diff --git a/docs/src/components/tailwind-config/typography/HalfLeading.tsx b/docs/src/components/tailwind-config/typography/HalfLeading.tsx new file mode 100644 index 000000000..d920461bc --- /dev/null +++ b/docs/src/components/tailwind-config/typography/HalfLeading.tsx @@ -0,0 +1,27 @@ +import { sizeClasses } from './utils' + +export const HalfLeading: React.FC = () => ( +
+
+

+ without half leading (default) +

+

preserve-half-leading

+
+ {Object.entries(sizeClasses).map(([sizeClassName]) => ( +
+

+ Abcあいう123 +

+

+ Abcあいう123 +

+
+ ))} +
+) diff --git a/docs/src/components/tailwind-config/typography/Sizes.tsx b/docs/src/components/tailwind-config/typography/Sizes.tsx new file mode 100644 index 000000000..7705d4b5a --- /dev/null +++ b/docs/src/components/tailwind-config/typography/Sizes.tsx @@ -0,0 +1,21 @@ +import { sizeClasses } from './utils' + +export const Sizes: React.FC = () => ( +
+ {Object.entries(sizeClasses).map(([className, value]) => ( +
+

{className}

+

+ charcoal はピクシブ株式会社のデザインシステムです。ここでは特に、Web + フロントエンドの実装に用いる npm パッケージ集のことを言います。 Lorem + ipsum dolor sit amet, consectetur adipiscing elit. +

+

+ font-size: {value['font-size']} /{' '} + line-height:{' '} + {value['line-height']} +

+
+ ))} +
+) diff --git a/docs/src/components/tailwind-config/typography/utils.ts b/docs/src/components/tailwind-config/typography/utils.ts new file mode 100644 index 000000000..34ab5f42e --- /dev/null +++ b/docs/src/components/tailwind-config/typography/utils.ts @@ -0,0 +1,55 @@ +import { config } from '@charcoal-ui/tailwind-config' +import { mapObject } from '@charcoal-ui/utils' + +type TailwindPlugin = { + handler: ({ + addBase, + addUtilities, + }: { + addBase: unknown + addUtilities: unknown + }) => void +} +type UtilityClasses = Record> + +/** + * TODO: + * Seek for some better way to find the plugin we need here + * from `config.plugins` array + */ +const typographyPlugin: TailwindPlugin = config.plugins + ? (config.plugins[0] as unknown as TailwindPlugin) + : { handler: () => void {} } + +const getUtilities = (plugin: TailwindPlugin) => { + let utilities: UtilityClasses = {} + + plugin.handler({ + addBase: () => { + /** + * We don't need these base styles as they gonna be + * applied to the `:root` element by Tailwind automatically + */ + }, + addUtilities: (args: UtilityClasses) => { + utilities = { ...utilities, ...args } + }, + }) + + return mapObject(utilities, (key, value) => [ + key.startsWith('.') ? key.slice(1) : key, + value, + ]) +} + +export const utilityClasses = getUtilities(typographyPlugin) + +type SizeClassValue = Readonly<{ + 'font-size': string + 'line-height': string +}> +export const sizeClasses: Record = Object.fromEntries( + Object.entries(utilityClasses).filter( + ([className]) => className !== 'preserve-half-leading' + ) +) as Record diff --git a/docs/src/pages/@charcoal-ui/tailwind-config/typography.page.tsx b/docs/src/pages/@charcoal-ui/tailwind-config/typography.page.tsx new file mode 100644 index 000000000..500501379 --- /dev/null +++ b/docs/src/pages/@charcoal-ui/tailwind-config/typography.page.tsx @@ -0,0 +1,14 @@ +import { NextPage } from 'next' +import { Sizes } from '../../../components/tailwind-config/typography/Sizes' +import { HalfLeading } from '../../../components/tailwind-config/typography/HalfLeading' + +const TypographyPage: NextPage = () => ( +
+

Sizes

+ + +

Half leading cancellation

+ +
+) +export default TypographyPage