@charcoal-ui/tailwind-config 1.0.1-alpha.0 → 1.0.1-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/_lib/compat.d.ts +14 -0
- package/dist/_lib/compat.d.ts.map +1 -0
- package/dist/docs/borderRadius/BorderRadius.d.ts +3 -0
- package/dist/docs/borderRadius/BorderRadius.d.ts.map +1 -0
- package/dist/docs/borderRadius/index.d.ts +3 -0
- package/dist/docs/borderRadius/index.d.ts.map +1 -0
- package/dist/docs/colors/Colors.d.ts +3 -0
- package/dist/docs/colors/Colors.d.ts.map +1 -0
- package/dist/docs/colors/TextBgColor.story.d.ts +27 -0
- package/dist/docs/colors/TextBgColor.story.d.ts.map +1 -0
- package/dist/docs/colors/TextColors.d.ts +3 -0
- package/dist/docs/colors/TextColors.d.ts.map +1 -0
- package/dist/docs/colors/index.d.ts +4 -0
- package/dist/docs/colors/index.d.ts.map +1 -0
- package/dist/docs/gradient/Gradients.d.ts +3 -0
- package/dist/docs/gradient/Gradients.d.ts.map +1 -0
- package/dist/docs/gradient/index.d.ts +10 -0
- package/dist/docs/gradient/index.d.ts.map +1 -0
- package/dist/docs/gradient/utils.d.ts +2 -0
- package/dist/docs/gradient/utils.d.ts.map +1 -0
- package/dist/docs/index.d.ts +9 -0
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/screens/Screens.d.ts +3 -0
- package/dist/docs/screens/Screens.d.ts.map +1 -0
- package/dist/docs/screens/index.d.ts +3 -0
- package/dist/docs/screens/index.d.ts.map +1 -0
- package/dist/docs/spacing/Spacing.d.ts +3 -0
- package/dist/docs/spacing/Spacing.d.ts.map +1 -0
- package/dist/docs/spacing/index.d.ts +3 -0
- package/dist/docs/spacing/index.d.ts.map +1 -0
- package/dist/docs/typography/HalfLeading.d.ts +3 -0
- package/dist/docs/typography/HalfLeading.d.ts.map +1 -0
- package/dist/docs/typography/Sizes.d.ts +3 -0
- package/dist/docs/typography/Sizes.d.ts.map +1 -0
- package/dist/docs/typography/index.d.ts +9 -0
- package/dist/docs/typography/index.d.ts.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/util.d.ts +32 -0
- package/dist/util.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/__snapshots__/index.test.ts.snap +320 -0
- package/src/_lib/compat.ts +12 -0
- package/src/docs/borderRadius/BorderRadius.tsx +27 -0
- package/src/docs/borderRadius/index.story.mdx +10 -0
- package/src/docs/borderRadius/index.ts +5 -0
- package/src/docs/colors/Colors.tsx +85 -0
- package/src/docs/colors/TextBgColor.story.tsx +41 -0
- package/src/docs/colors/TextColors.tsx +22 -0
- package/src/docs/colors/index.story.mdx +27 -0
- package/src/docs/colors/index.ts +6 -0
- package/src/docs/gradient/Gradients.tsx +67 -0
- package/src/docs/gradient/index.story.mdx +12 -0
- package/src/docs/gradient/index.ts +26 -0
- package/src/docs/gradient/utils.ts +37 -0
- package/src/docs/index.ts +34 -0
- package/src/docs/screens/Screens.tsx +21 -0
- package/src/docs/screens/index.story.mdx +10 -0
- package/src/docs/screens/index.ts +5 -0
- package/src/docs/spacing/Spacing.tsx +17 -0
- package/src/docs/spacing/index.story.mdx +10 -0
- package/src/docs/spacing/index.ts +5 -0
- package/src/docs/typography/HalfLeading.tsx +28 -0
- package/src/docs/typography/Sizes.tsx +22 -0
- package/src/docs/typography/index.story.mdx +26 -0
- package/src/docs/typography/index.ts +26 -0
- package/src/util.ts +32 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { borderRadius } from '.'
|
|
3
|
+
|
|
4
|
+
export const BorderRadius: React.FC = () => {
|
|
5
|
+
return (
|
|
6
|
+
<div className="space-y-40">
|
|
7
|
+
{Object.entries(borderRadius).map(([key, value]) => (
|
|
8
|
+
<div key={key}>
|
|
9
|
+
<p className="typography-14 text-text2">rounded-{key}</p>
|
|
10
|
+
<div className="space-x-16 flex">
|
|
11
|
+
<div
|
|
12
|
+
className={`bg-surface4 rounded-${key} h-64`}
|
|
13
|
+
style={{ width: '64px' }}
|
|
14
|
+
></div>
|
|
15
|
+
<div
|
|
16
|
+
className={`bg-surface4 rounded-${key} h-64`}
|
|
17
|
+
style={{ width: '272px' }}
|
|
18
|
+
></div>
|
|
19
|
+
</div>
|
|
20
|
+
<p className="typography-12 text-text3">
|
|
21
|
+
border-radius: <span className="text-text2">{value}</span>
|
|
22
|
+
</p>
|
|
23
|
+
</div>
|
|
24
|
+
))}
|
|
25
|
+
</div>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { EffectType } from '@charcoal-ui/theme'
|
|
3
|
+
import { colors } from '.'
|
|
4
|
+
|
|
5
|
+
const effectTypes: { [type in EffectType]: null } = {
|
|
6
|
+
hover: null,
|
|
7
|
+
press: null,
|
|
8
|
+
disabled: null,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ColorBox: React.FC<{
|
|
12
|
+
bgColorClass: string
|
|
13
|
+
label: string
|
|
14
|
+
emphasizeLabelByDefault?: boolean
|
|
15
|
+
}> = ({ bgColorClass, label, emphasizeLabelByDefault = false }) => (
|
|
16
|
+
<div className="group grow basis-0 space-y-8">
|
|
17
|
+
<p
|
|
18
|
+
className={`typography-14 ${
|
|
19
|
+
emphasizeLabelByDefault ? 'text-text2' : 'text-text3'
|
|
20
|
+
} group-hover:text-text2 transition-colors`}
|
|
21
|
+
>
|
|
22
|
+
{label}
|
|
23
|
+
</p>
|
|
24
|
+
<div className="relative h-64 w-full">
|
|
25
|
+
<div
|
|
26
|
+
/**
|
|
27
|
+
* Display checker pattern for visualizing colors with transparency
|
|
28
|
+
*/
|
|
29
|
+
className="absolute top-0 right-0 h-full w-6/12"
|
|
30
|
+
aria-hidden="true"
|
|
31
|
+
style={{
|
|
32
|
+
backgroundImage:
|
|
33
|
+
'linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(135deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(135deg, transparent 75%, #ccc 75%)',
|
|
34
|
+
backgroundSize: '12px 12px',
|
|
35
|
+
backgroundPosition: '0 0, 6px 0, 6px -6px, 0 6px',
|
|
36
|
+
}}
|
|
37
|
+
></div>
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
className={`absolute top-0 left-0 h-full w-full border border-r-0 group-last:border-r border-default cursor-pointer ${bgColorClass}`}
|
|
41
|
+
onClick={() => {
|
|
42
|
+
void navigator.clipboard.writeText(bgColorClass)
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<span className="opacity-0 group-hover:opacity-100 transition-opacity typography-14 text-text2">
|
|
46
|
+
Click to copy the class
|
|
47
|
+
</span>
|
|
48
|
+
</button>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
export const Colors: React.FC = () => {
|
|
54
|
+
return (
|
|
55
|
+
<div className="space-y-24">
|
|
56
|
+
{Object.entries(colors).map(([colorName, values]) => (
|
|
57
|
+
<div className="flex" key={colorName}>
|
|
58
|
+
{typeof values === 'object' && 'DEFAULT' in values ? (
|
|
59
|
+
<>
|
|
60
|
+
<ColorBox
|
|
61
|
+
bgColorClass={`bg-${colorName}`}
|
|
62
|
+
label={colorName}
|
|
63
|
+
emphasizeLabelByDefault
|
|
64
|
+
/>
|
|
65
|
+
{Object.keys(effectTypes).map((modifier) =>
|
|
66
|
+
modifier in values ? (
|
|
67
|
+
<ColorBox
|
|
68
|
+
bgColorClass={`bg-${colorName}-${modifier}`}
|
|
69
|
+
label={`-${modifier}`}
|
|
70
|
+
/>
|
|
71
|
+
) : null
|
|
72
|
+
)}
|
|
73
|
+
</>
|
|
74
|
+
) : (
|
|
75
|
+
<ColorBox
|
|
76
|
+
bgColorClass={`bg-${colorName}`}
|
|
77
|
+
label={colorName}
|
|
78
|
+
emphasizeLabelByDefault
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
))}
|
|
83
|
+
</div>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { Story } from '../../_lib/compat'
|
|
3
|
+
|
|
4
|
+
import { colors } from '.'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'tailwind-config/Colors/Text bg color',
|
|
8
|
+
argTypes: {
|
|
9
|
+
textColorClass: {
|
|
10
|
+
control: {
|
|
11
|
+
type: 'select',
|
|
12
|
+
options: Object.keys(colors).map((color) => `text-${color}`),
|
|
13
|
+
},
|
|
14
|
+
defaultValue: 'text-text1',
|
|
15
|
+
},
|
|
16
|
+
bgColorClass: {
|
|
17
|
+
control: {
|
|
18
|
+
type: 'select',
|
|
19
|
+
options: Object.keys(colors).map((color) => `bg-${color}`),
|
|
20
|
+
},
|
|
21
|
+
defaultValue: 'bg-background1',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Props = Readonly<{
|
|
27
|
+
textColorClass: string
|
|
28
|
+
bgColorClass: string
|
|
29
|
+
}>
|
|
30
|
+
|
|
31
|
+
export const Playground: Story<Props> = ({ textColorClass, bgColorClass }) => (
|
|
32
|
+
<div className={`${bgColorClass} p-64 max-w-2xl`}>
|
|
33
|
+
<p className={`typography-20 ${textColorClass}`}>
|
|
34
|
+
charcoal はピクシブ株式会社のデザインシステムです。ここでは特に、Web
|
|
35
|
+
フロントエンドの実装に用いる npm パッケージ集のことを言います。Lorem ipsum
|
|
36
|
+
dolor sit amet, consectetur adipiscing elit. Aliquam at odio bibendum nisl
|
|
37
|
+
mollis eleifend et quis turpis. Quisque dignissim porta justo ut
|
|
38
|
+
convallis.dipiscing elit.
|
|
39
|
+
</p>
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { colors } from '.'
|
|
3
|
+
|
|
4
|
+
export const TextColors: React.FC = () => (
|
|
5
|
+
<div className="space-y-24">
|
|
6
|
+
{Object.keys(colors).map((colorName) => (
|
|
7
|
+
<div key={colorName}>
|
|
8
|
+
<p className="typography-14 text-text2 mb-4">text-{colorName}</p>
|
|
9
|
+
<div className={`relative z-0`}>
|
|
10
|
+
<div
|
|
11
|
+
className="absolute top-0 right-0 h-full w-6/12 bg-surface8 z-[-1]"
|
|
12
|
+
aria-hidden="true"
|
|
13
|
+
></div>
|
|
14
|
+
<p className={`typography-20 text-${colorName}`}>
|
|
15
|
+
charcoal はピクシブ株式会社のデザインシステムです。ここでは特に、Web
|
|
16
|
+
フロントエンドの実装に用いる npm パッケージ集のことを言います。
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Meta, Story } from '@storybook/addon-docs'
|
|
2
|
+
import { Colors, TextColors } from '.'
|
|
3
|
+
|
|
4
|
+
<Meta title="tailwind-config/Colors/Doc" component={[Colors, TextColors]} />
|
|
5
|
+
|
|
6
|
+
# Colors
|
|
7
|
+
|
|
8
|
+
<br />
|
|
9
|
+
|
|
10
|
+
## Bg colors
|
|
11
|
+
|
|
12
|
+
<br />
|
|
13
|
+
|
|
14
|
+
<Story name="Colors">
|
|
15
|
+
<Colors />
|
|
16
|
+
</Story>
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
<br />
|
|
20
|
+
|
|
21
|
+
## Text colors
|
|
22
|
+
|
|
23
|
+
<br />
|
|
24
|
+
|
|
25
|
+
<Story name="Text colors">
|
|
26
|
+
<TextColors />
|
|
27
|
+
</Story>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { utilityClasses, directions, effectTypes } from '.'
|
|
3
|
+
import { getUniqueGradientNames } from './utils'
|
|
4
|
+
|
|
5
|
+
const GradientBox: React.FC<{
|
|
6
|
+
gradientClassName: string
|
|
7
|
+
label: string
|
|
8
|
+
emphasizeLabelByDefault?: boolean
|
|
9
|
+
}> = ({ gradientClassName, label, emphasizeLabelByDefault = false }) => (
|
|
10
|
+
<div className="group grow basis-0">
|
|
11
|
+
<p
|
|
12
|
+
className={`typography-14 ${
|
|
13
|
+
emphasizeLabelByDefault ? 'text-text2' : 'text-text3'
|
|
14
|
+
} group-hover:text-text2 transition-colors`}
|
|
15
|
+
>
|
|
16
|
+
{label}
|
|
17
|
+
</p>
|
|
18
|
+
<button
|
|
19
|
+
type="button"
|
|
20
|
+
className={`${gradientClassName} h-64 w-full border-none cursor-pointer`}
|
|
21
|
+
onClick={() => {
|
|
22
|
+
void navigator.clipboard.writeText(gradientClassName)
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
<span className="opacity-0 group-hover:opacity-100 transition-opacity typography-14 text-text2">
|
|
26
|
+
Click to copy the class
|
|
27
|
+
</span>
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
export const Gradients: React.FC = () => {
|
|
33
|
+
const utilityClassNames = Object.keys(utilityClasses)
|
|
34
|
+
const uniqueGradientNames = getUniqueGradientNames(utilityClassNames)
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="space-y-64">
|
|
38
|
+
{uniqueGradientNames.map((gradientName) => (
|
|
39
|
+
<div className="space-y-24" key={gradientName}>
|
|
40
|
+
{directions.map((direction) => (
|
|
41
|
+
<div className="flex" key={direction}>
|
|
42
|
+
{utilityClassNames.includes(`${gradientName}-${direction}`) && (
|
|
43
|
+
<GradientBox
|
|
44
|
+
gradientClassName={`${gradientName}-${direction}`}
|
|
45
|
+
label={`${gradientName}-${direction}`}
|
|
46
|
+
emphasizeLabelByDefault
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
49
|
+
{Object.keys(effectTypes).map(
|
|
50
|
+
(effectType) =>
|
|
51
|
+
utilityClassNames.includes(
|
|
52
|
+
`${gradientName}-${direction}-${effectType}`
|
|
53
|
+
) && (
|
|
54
|
+
<GradientBox
|
|
55
|
+
gradientClassName={`${gradientName}-${direction}-${effectType}`}
|
|
56
|
+
label={`-${effectType}`}
|
|
57
|
+
key={effectType}
|
|
58
|
+
/>
|
|
59
|
+
)
|
|
60
|
+
)}
|
|
61
|
+
</div>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EffectType } from '@charcoal-ui/theme'
|
|
2
|
+
import { config } from '../../'
|
|
3
|
+
import { TailwindPlugin, getUtilities } from '../'
|
|
4
|
+
|
|
5
|
+
export { Gradients } from './Gradients'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TODO:
|
|
9
|
+
* Seek for some better way to find the plugin we need here
|
|
10
|
+
* from `config.plugins` array
|
|
11
|
+
*/
|
|
12
|
+
const gradientPlugin: TailwindPlugin = config.plugins
|
|
13
|
+
? (config.plugins[2] as unknown as TailwindPlugin)
|
|
14
|
+
: { handler: () => void {} }
|
|
15
|
+
|
|
16
|
+
export const utilityClasses = getUtilities(gradientPlugin)
|
|
17
|
+
|
|
18
|
+
export const directions = ['top', 'bottom', 'right', 'left'] as const
|
|
19
|
+
export type Direction = typeof directions[number]
|
|
20
|
+
|
|
21
|
+
export type { EffectType }
|
|
22
|
+
export const effectTypes: { [type in EffectType]: null } = {
|
|
23
|
+
hover: null,
|
|
24
|
+
press: null,
|
|
25
|
+
disabled: null,
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { directions } from '.'
|
|
2
|
+
|
|
3
|
+
export const getUniqueGradientNames = (utilityClasses: string[]): string[] => {
|
|
4
|
+
return Array.from(
|
|
5
|
+
new Set(
|
|
6
|
+
utilityClasses
|
|
7
|
+
.map((className) => {
|
|
8
|
+
/**
|
|
9
|
+
* like `['bg', 'surface5', 'bottom', 'disabled']`
|
|
10
|
+
*/
|
|
11
|
+
const classNameParts = className.split('-')
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* like `bottom`
|
|
15
|
+
*/
|
|
16
|
+
const directionInClassName = directions.find((direction) =>
|
|
17
|
+
classNameParts.includes(direction)
|
|
18
|
+
)
|
|
19
|
+
if (!directionInClassName) return null
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* like `['bg', 'surface5']`
|
|
23
|
+
*/
|
|
24
|
+
const classNameWithoutModifiers = classNameParts.slice(
|
|
25
|
+
0,
|
|
26
|
+
classNameParts.indexOf(directionInClassName)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* like `bg-surface5`
|
|
31
|
+
*/
|
|
32
|
+
return classNameWithoutModifiers.join('-')
|
|
33
|
+
})
|
|
34
|
+
.filter((value): value is string => typeof value === 'string')
|
|
35
|
+
).values()
|
|
36
|
+
)
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { mapObject } from '../util'
|
|
2
|
+
|
|
3
|
+
export type TailwindPlugin = {
|
|
4
|
+
handler: ({
|
|
5
|
+
addBase,
|
|
6
|
+
addUtilities,
|
|
7
|
+
}: {
|
|
8
|
+
addBase: unknown
|
|
9
|
+
addUtilities: unknown
|
|
10
|
+
}) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type UtilityClasses = Record<string, Record<string, unknown>>
|
|
14
|
+
|
|
15
|
+
export const getUtilities = (plugin: TailwindPlugin) => {
|
|
16
|
+
let utilities: UtilityClasses = {}
|
|
17
|
+
|
|
18
|
+
plugin.handler({
|
|
19
|
+
addBase: () => {
|
|
20
|
+
/**
|
|
21
|
+
* We don't need these base styles as they gonna be
|
|
22
|
+
* applied to the `:root` element by Tailwind automatically
|
|
23
|
+
*/
|
|
24
|
+
},
|
|
25
|
+
addUtilities: (args: UtilityClasses) => {
|
|
26
|
+
utilities = { ...utilities, ...args }
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return mapObject(utilities, (key, value) => [
|
|
31
|
+
key.startsWith('.') ? key.slice(1) : key,
|
|
32
|
+
value,
|
|
33
|
+
])
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { screens } from '.'
|
|
3
|
+
|
|
4
|
+
export const Screens: React.FC = () => {
|
|
5
|
+
return (
|
|
6
|
+
<div className="space-y-40">
|
|
7
|
+
{Object.entries(screens).map(
|
|
8
|
+
([screenName, value]) =>
|
|
9
|
+
typeof value === 'string' && (
|
|
10
|
+
<div key={screenName}>
|
|
11
|
+
<p className="typography-14 text-text2">{screenName}</p>
|
|
12
|
+
<div className="bg-surface4 h-64" style={{ width: value }}></div>
|
|
13
|
+
<p className="typography-12 text-text3">
|
|
14
|
+
@media (<span className="text-text2">min-width: {value}</span>)
|
|
15
|
+
</p>
|
|
16
|
+
</div>
|
|
17
|
+
)
|
|
18
|
+
)}
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { spacing } from '.'
|
|
3
|
+
|
|
4
|
+
export const Spacing: React.FC = () => {
|
|
5
|
+
return (
|
|
6
|
+
<div className="space-y-40">
|
|
7
|
+
{Object.keys(spacing).map((space) => (
|
|
8
|
+
<div key={space}>
|
|
9
|
+
<p className="typography-14 text-text2">p-{space}</p>
|
|
10
|
+
<div className={`bg-surface3 p-${space} w-[min-content]`}>
|
|
11
|
+
<div className="bg-brand h-40" style={{ width: '40px' }}></div>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
))}
|
|
15
|
+
</div>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { sizeClasses } from '.'
|
|
3
|
+
|
|
4
|
+
export const HalfLeading: React.FC = () => (
|
|
5
|
+
<div className="p-40 bg-brand-disabled">
|
|
6
|
+
<div className="flex items-center space-x-16">
|
|
7
|
+
<p className="typography-14 text-text1 w-6/12 text-right">
|
|
8
|
+
without half leading (default)
|
|
9
|
+
</p>
|
|
10
|
+
<p className="typography-14 text-text1 w-6/12">preserve-half-leading</p>
|
|
11
|
+
</div>
|
|
12
|
+
{Object.entries(sizeClasses).map(([sizeClassName]) => (
|
|
13
|
+
<div
|
|
14
|
+
key={sizeClassName}
|
|
15
|
+
className="flex items-center justify-center space-x-16"
|
|
16
|
+
>
|
|
17
|
+
<p className={`${sizeClassName} bg-background1 text-text1`}>
|
|
18
|
+
Abcあいう123
|
|
19
|
+
</p>
|
|
20
|
+
<p
|
|
21
|
+
className={`${sizeClassName} bg-background1 text-text1 preserve-half-leading`}
|
|
22
|
+
>
|
|
23
|
+
Abcあいう123
|
|
24
|
+
</p>
|
|
25
|
+
</div>
|
|
26
|
+
))}
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { sizeClasses } from '.'
|
|
3
|
+
|
|
4
|
+
export const Sizes: React.FC = () => (
|
|
5
|
+
<div className="space-y-64">
|
|
6
|
+
{Object.entries(sizeClasses).map(([className, value]) => (
|
|
7
|
+
<div key={className}>
|
|
8
|
+
<p className="typography-14 text-text2">{className}</p>
|
|
9
|
+
<p className={`${className} text-text1`}>
|
|
10
|
+
charcoal はピクシブ株式会社のデザインシステムです。ここでは特に、Web
|
|
11
|
+
フロントエンドの実装に用いる npm パッケージ集のことを言います。 Lorem
|
|
12
|
+
ipsum dolor sit amet, consectetur adipiscing elit.
|
|
13
|
+
</p>
|
|
14
|
+
<p className="typography-12 text-text3">
|
|
15
|
+
font-size: <span className="text-text2">{value['font-size']}</span> /{' '}
|
|
16
|
+
line-height:{' '}
|
|
17
|
+
<span className="text-text2">{value['line-height']}</span>
|
|
18
|
+
</p>
|
|
19
|
+
</div>
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Meta, Story } from '@storybook/addon-docs'
|
|
2
|
+
import { Sizes, HalfLeading } from '.'
|
|
3
|
+
|
|
4
|
+
<Meta title="tailwind-config/Typography" component={[Sizes]} />
|
|
5
|
+
|
|
6
|
+
# Typography
|
|
7
|
+
|
|
8
|
+
<br />
|
|
9
|
+
|
|
10
|
+
## Sizes
|
|
11
|
+
|
|
12
|
+
<br />
|
|
13
|
+
|
|
14
|
+
<Story name="Sizes">
|
|
15
|
+
<Sizes />
|
|
16
|
+
</Story>
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
|
|
20
|
+
## Half leading cancellation
|
|
21
|
+
|
|
22
|
+
<br />
|
|
23
|
+
|
|
24
|
+
<Story name="Half leading">
|
|
25
|
+
<HalfLeading />
|
|
26
|
+
</Story>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { config } from '../../'
|
|
2
|
+
import { TailwindPlugin, getUtilities } from '../'
|
|
3
|
+
|
|
4
|
+
export { Sizes } from './Sizes'
|
|
5
|
+
export { HalfLeading } from './HalfLeading'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TODO:
|
|
9
|
+
* Seek for some better way to find the plugin we need here
|
|
10
|
+
* from `config.plugins` array
|
|
11
|
+
*/
|
|
12
|
+
const typographyPlugin: TailwindPlugin = config.plugins
|
|
13
|
+
? (config.plugins[0] as unknown as TailwindPlugin)
|
|
14
|
+
: { handler: () => void {} }
|
|
15
|
+
|
|
16
|
+
export const utilityClasses = getUtilities(typographyPlugin)
|
|
17
|
+
|
|
18
|
+
type SizeClassValue = Readonly<{
|
|
19
|
+
'font-size': string
|
|
20
|
+
'line-height': string
|
|
21
|
+
}>
|
|
22
|
+
export const sizeClasses: Record<string, SizeClassValue> = Object.fromEntries(
|
|
23
|
+
Object.entries(utilityClasses).filter(
|
|
24
|
+
([className]) => className !== 'preserve-half-leading'
|
|
25
|
+
)
|
|
26
|
+
) as Record<string, SizeClassValue>
|
package/src/util.ts
CHANGED
|
@@ -66,6 +66,12 @@ Got: ${JSON.stringify(Array.from(effectKeys))}`)
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @example
|
|
71
|
+
* ```js
|
|
72
|
+
* mapKeys({ a: 'aa', b: 'bb' }, (key) => key.toUpperCase()) // => { A: "aa", B: "bb" }
|
|
73
|
+
* ````
|
|
74
|
+
*/
|
|
69
75
|
export function mapKeys<V, K extends string>(
|
|
70
76
|
object: Record<string, V>,
|
|
71
77
|
callback: (key: string) => K
|
|
@@ -75,6 +81,14 @@ export function mapKeys<V, K extends string>(
|
|
|
75
81
|
) as Record<K, V>
|
|
76
82
|
}
|
|
77
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @example
|
|
86
|
+
* ```js
|
|
87
|
+
* mapObject({ a: 'aa', b: 'bb', c: 'cc' }, (key, value) =>
|
|
88
|
+
* key === 'b' ? undefined : [key + '1', value.toUpperCase()]
|
|
89
|
+
* ) // => { a1: "AA", c1: "CC" }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
78
92
|
export function mapObject<
|
|
79
93
|
SourceKey extends string,
|
|
80
94
|
SourceValue,
|
|
@@ -99,6 +113,15 @@ export function mapObject<
|
|
|
99
113
|
) as Record<DestKey, DestValue>
|
|
100
114
|
}
|
|
101
115
|
|
|
116
|
+
/**
|
|
117
|
+
* @example
|
|
118
|
+
* ```js
|
|
119
|
+
* flatMapObject({ a: 'aa', b: 'bb' }, (key, value) => [
|
|
120
|
+
* [key + '1', value + '1'],
|
|
121
|
+
* [key + '2', value + '2'],
|
|
122
|
+
* ]) // => { a1: "aa1", a2: "aa2", b1: "bb1", b2: "bb2" }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
102
125
|
export function flatMapObject<
|
|
103
126
|
SourceKey extends string,
|
|
104
127
|
SourceValue,
|
|
@@ -115,6 +138,15 @@ export function flatMapObject<
|
|
|
115
138
|
) as Record<DestKey, DestValue>
|
|
116
139
|
}
|
|
117
140
|
|
|
141
|
+
/**
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* filterObject(
|
|
145
|
+
* { a: 'aa', b: 'bb', c: 'cc' },
|
|
146
|
+
* (value): value is string => value !== 'bb'
|
|
147
|
+
* ) // => { a: "aa", c: "cc" }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
118
150
|
export function filterObject<Source, Dest extends Source>(
|
|
119
151
|
source: Record<string, Source>,
|
|
120
152
|
fn: (value: Source) => value is Dest
|