@charcoal-ui/styled 3.9.1 → 3.10.1-beta.0
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/dist/index.cjs.js +177 -11
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +174 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.story.d.ts +0 -8
- package/dist/index.story.d.ts.map +1 -1
- package/dist/index.test.d.ts +5 -0
- package/dist/index.test.d.ts.map +1 -1
- package/dist/storyHelper.d.ts +2 -1
- package/dist/storyHelper.d.ts.map +1 -1
- package/dist/styles/assertiveRingCss.d.ts +2 -0
- package/dist/styles/assertiveRingCss.d.ts.map +1 -0
- package/dist/styles/disabledCss.d.ts +2 -0
- package/dist/styles/disabledCss.d.ts.map +1 -0
- package/dist/utils/CharcoalStyledTheme.d.ts +35 -0
- package/dist/utils/CharcoalStyledTheme.d.ts.map +1 -0
- package/dist/utils/addThemeUtils.d.ts +8 -0
- package/dist/utils/addThemeUtils.d.ts.map +1 -0
- package/dist/utils/gap.d.ts +7 -0
- package/dist/utils/gap.d.ts.map +1 -0
- package/dist/utils/helpers/SpacingType.d.ts +3 -0
- package/dist/utils/helpers/SpacingType.d.ts.map +1 -0
- package/dist/utils/helpers/pxIfNum.d.ts +2 -0
- package/dist/utils/helpers/pxIfNum.d.ts.map +1 -0
- package/dist/utils/margin.d.ts +11 -0
- package/dist/utils/margin.d.ts.map +1 -0
- package/dist/utils/padding.d.ts +11 -0
- package/dist/utils/padding.d.ts.map +1 -0
- package/dist/utils/typographyCss.d.ts +2 -0
- package/dist/utils/typographyCss.d.ts.map +1 -0
- package/package.json +8 -6
- package/src/__snapshots__/index.story.storyshot +88 -691
- package/src/__snapshots__/index.test.tsx.snap +177 -664
- package/src/index.story.tsx +81 -272
- package/src/index.test.tsx +55 -5
- package/src/index.ts +12 -1
- package/src/storyHelper.ts +8 -5
- package/src/styles/assertiveRingCss.ts +5 -0
- package/src/styles/disabledCss.ts +9 -0
- package/src/themeUtils.mdx +44 -0
- package/src/utils/CharcoalStyledTheme.ts +47 -0
- package/src/utils/addThemeUtils.ts +52 -0
- package/src/utils/gap.ts +28 -0
- package/src/utils/helpers/SpacingType.ts +3 -0
- package/src/utils/helpers/pxIfNum.ts +5 -0
- package/src/utils/margin.ts +58 -0
- package/src/utils/padding.ts +58 -0
- package/src/utils/typographyCss.ts +39 -0
package/src/index.story.tsx
CHANGED
|
@@ -1,304 +1,113 @@
|
|
|
1
|
-
import styled, {
|
|
2
|
-
import { createTheme, ThemeProp, defineThemeVariables } from '.'
|
|
3
|
-
import { disabledSelector } from '@charcoal-ui/utils'
|
|
1
|
+
import styled, { ThemeProvider } from 'styled-components'
|
|
4
2
|
import { MyTheme, myTheme } from './storyHelper'
|
|
5
3
|
|
|
6
4
|
export default {
|
|
7
|
-
title: 'styled',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare module 'react' {
|
|
11
|
-
interface Attributes {
|
|
12
|
-
css?: CSSProp<DefaultTheme> | ThemeProp<DefaultTheme>
|
|
13
|
-
}
|
|
5
|
+
title: 'styled/example',
|
|
14
6
|
}
|
|
15
7
|
|
|
16
8
|
declare module 'styled-components' {
|
|
17
9
|
export interface DefaultTheme extends MyTheme {}
|
|
18
10
|
}
|
|
19
11
|
|
|
20
|
-
const theme = createTheme<DefaultTheme>()
|
|
21
|
-
|
|
22
12
|
export const Example = () => (
|
|
23
13
|
<ThemeProvider theme={myTheme}>
|
|
24
|
-
<
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
</
|
|
47
|
-
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<
|
|
52
|
-
</
|
|
53
|
-
|
|
54
|
-
<TextField value="text field" />
|
|
55
|
-
<TextField value="disabled" disabled />
|
|
56
|
-
<TextField value="invalid" assertive />
|
|
57
|
-
</InputContainer>
|
|
58
|
-
<BorderedBox>Border</BorderedBox>
|
|
59
|
-
<GradientBox>Gradient</GradientBox>
|
|
60
|
-
<WarningGradientBox>Gradient (Warning)</WarningGradientBox>
|
|
61
|
-
<TailwindLike />
|
|
62
|
-
<FixBox>
|
|
63
|
-
<FullBox>Full width</FullBox>
|
|
64
|
-
</FixBox>
|
|
65
|
-
<LocalTheme>This is actually text1 !</LocalTheme>
|
|
66
|
-
</Container>
|
|
14
|
+
<RootDiv>
|
|
15
|
+
<Bg1Div>
|
|
16
|
+
<TypographyDiv>
|
|
17
|
+
{'${({ theme }) => theme.utils.typography(14, true)}'}
|
|
18
|
+
</TypographyDiv>
|
|
19
|
+
</Bg1Div>
|
|
20
|
+
|
|
21
|
+
<Bg1Div>
|
|
22
|
+
<MarginDiv>
|
|
23
|
+
<Pre>
|
|
24
|
+
<Code>
|
|
25
|
+
{`\${({ theme }) => [
|
|
26
|
+
theme.utils.margin(16, 'auto'),
|
|
27
|
+
theme.utils.padding(4, 8, 16, 24),
|
|
28
|
+
]}`}
|
|
29
|
+
</Code>
|
|
30
|
+
</Pre>
|
|
31
|
+
</MarginDiv>
|
|
32
|
+
</Bg1Div>
|
|
33
|
+
|
|
34
|
+
<Bg1Div>
|
|
35
|
+
<AssertiveRingDiv>{'theme.utils.assertiveRingCss'}</AssertiveRingDiv>
|
|
36
|
+
</Bg1Div>
|
|
37
|
+
|
|
38
|
+
<Bg1Div>
|
|
39
|
+
<StyledButton>{'theme.utils.focusVisibleFocusRingCss'}</StyledButton>
|
|
40
|
+
|
|
41
|
+
<StyledButton disabled>{'theme.utils.disabledCss'}</StyledButton>
|
|
42
|
+
</Bg1Div>
|
|
43
|
+
</RootDiv>
|
|
67
44
|
</ThemeProvider>
|
|
68
45
|
)
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
o.bg.mycolor.hover.press,
|
|
79
|
-
o.font.text5.hover.press,
|
|
80
|
-
o.typography(14).bold,
|
|
81
|
-
o.padding.all(16),
|
|
82
|
-
o.borderRadius(8),
|
|
83
|
-
])}
|
|
84
|
-
>
|
|
85
|
-
Tailwind like
|
|
86
|
-
</div>
|
|
87
|
-
</div>
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
const Container = styled.div``
|
|
91
|
-
|
|
92
|
-
const LeftTopPadding = styled.div`
|
|
93
|
-
/* 配列で複数のスタイルを返すこともできます */
|
|
94
|
-
${theme((o) => [
|
|
95
|
-
o.bg.surface3,
|
|
96
|
-
o.font.text4,
|
|
97
|
-
o.typography(32).monospace,
|
|
98
|
-
o.margin.vertical(24),
|
|
99
|
-
o.padding.left(64).top(64),
|
|
100
|
-
])}
|
|
47
|
+
const RootDiv = styled.div`
|
|
48
|
+
${({ theme }) => theme.utils.gap(40)}
|
|
49
|
+
color: ${({ theme }) => theme.color.text1};
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
white-space: nowrap;
|
|
53
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
|
54
|
+
'Liberation Mono', 'Courier New', monospace;
|
|
101
55
|
`
|
|
102
56
|
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
o.bg.surface2,
|
|
106
|
-
o.font.text2,
|
|
107
|
-
o.typography(20).bold,
|
|
108
|
-
o.padding.all(40),
|
|
109
|
-
o.margin.vertical(24),
|
|
110
|
-
])}
|
|
57
|
+
const Pre = styled.pre`
|
|
58
|
+
margin: 0;
|
|
111
59
|
`
|
|
112
60
|
|
|
113
|
-
const
|
|
114
|
-
|
|
61
|
+
const Code = styled.code`
|
|
62
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
|
63
|
+
'Liberation Mono', 'Courier New', monospace;
|
|
115
64
|
`
|
|
116
65
|
|
|
117
|
-
const
|
|
118
|
-
${theme
|
|
119
|
-
o.bg.surface4,
|
|
120
|
-
o.font.text5,
|
|
121
|
-
o.typography(20).bold,
|
|
122
|
-
o.height.px(40),
|
|
123
|
-
])};
|
|
66
|
+
const TypographyDiv = styled.div`
|
|
67
|
+
${({ theme }) => theme.utils.typography(14, true)}
|
|
124
68
|
`
|
|
125
69
|
|
|
126
|
-
const
|
|
127
|
-
${theme
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
]
|
|
70
|
+
const MarginDiv = styled.div`
|
|
71
|
+
color: ${({ theme }) => theme.color.text1};
|
|
72
|
+
background-color: ${({ theme }) => theme.color.background2};
|
|
73
|
+
border: 1px solid ${({ theme }) => theme.color.border};
|
|
74
|
+
${({ theme }) => [
|
|
75
|
+
theme.utils.margin(16, 'auto'),
|
|
76
|
+
theme.utils.padding(4, 8, 16, 24),
|
|
77
|
+
]}
|
|
134
78
|
`
|
|
135
79
|
|
|
136
|
-
const
|
|
137
|
-
|
|
80
|
+
const Bg1Div = styled.div`
|
|
81
|
+
box-sizing: border-box;
|
|
82
|
+
display: flex;
|
|
83
|
+
background-color: ${({ theme }) => theme.color.background1};
|
|
84
|
+
border: 1px solid ${({ theme }) => theme.color.border};
|
|
85
|
+
overflow-x: auto;
|
|
86
|
+
overflow-y: hidden;
|
|
138
87
|
`
|
|
139
88
|
|
|
140
|
-
const
|
|
141
|
-
${theme
|
|
142
|
-
|
|
143
|
-
o.font.text5.hover.press,
|
|
144
|
-
o.typography(20).bold,
|
|
145
|
-
o.margin.top(64).bottom(24),
|
|
146
|
-
o.padding.all(64),
|
|
147
|
-
])}
|
|
89
|
+
const AssertiveRingDiv = styled.div`
|
|
90
|
+
${({ theme }) => [theme.utils.assertiveRingCss, theme.utils.margin(8)]}
|
|
91
|
+
transition: 0.2s box-shadow;
|
|
148
92
|
`
|
|
149
93
|
|
|
150
|
-
const
|
|
151
|
-
${theme
|
|
152
|
-
|
|
153
|
-
|
|
94
|
+
const StyledButton = styled.button`
|
|
95
|
+
${({ theme }) => [
|
|
96
|
+
theme.utils.focusVisibleFocusRingCss,
|
|
97
|
+
theme.utils.disabledCss,
|
|
98
|
+
theme.utils.padding(0, 16),
|
|
99
|
+
theme.utils.margin(16),
|
|
100
|
+
]}
|
|
101
|
+
transition: 0.2s box-shadow;
|
|
154
102
|
|
|
155
|
-
const WithoutHalfLeading = styled.div`
|
|
156
|
-
${theme((o) => [
|
|
157
|
-
o.bg.surface3,
|
|
158
|
-
o.typography(16).bold,
|
|
159
|
-
o.padding.all(24),
|
|
160
|
-
o.margin.vertical(24),
|
|
161
|
-
])}
|
|
162
|
-
`
|
|
163
|
-
|
|
164
|
-
const WithHalfLeading = styled.div`
|
|
165
|
-
${theme((o) => [
|
|
166
|
-
o.bg.surface3,
|
|
167
|
-
o.typography(16).bold.preserveHalfLeading,
|
|
168
|
-
o.padding.all(24),
|
|
169
|
-
o.margin.vertical(24),
|
|
170
|
-
])}
|
|
171
|
-
`
|
|
172
|
-
|
|
173
|
-
const FixedSizeBox = styled.div`
|
|
174
|
-
${theme((o) => [
|
|
175
|
-
o.bg.surface3,
|
|
176
|
-
o.font.text2,
|
|
177
|
-
o.typography(20).bold,
|
|
178
|
-
o.width.column(3),
|
|
179
|
-
o.height.px(64),
|
|
180
|
-
o.margin.vertical(24),
|
|
181
|
-
])}
|
|
182
|
-
`
|
|
183
|
-
|
|
184
|
-
const InputContainer = styled.div`
|
|
185
|
-
display: grid;
|
|
186
|
-
grid-auto-flow: column;
|
|
187
|
-
justify-content: start;
|
|
188
|
-
gap: 16px;
|
|
189
|
-
|
|
190
|
-
${theme((o) => o.margin.vertical(24))}
|
|
191
|
-
`
|
|
192
|
-
|
|
193
|
-
const Button = styled.button`
|
|
194
|
-
font: inherit;
|
|
195
|
-
appearance: none;
|
|
196
|
-
border-style: none;
|
|
197
103
|
cursor: pointer;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
o.typography(14).bold,
|
|
207
|
-
o.height.px(40),
|
|
208
|
-
o.padding.horizontal(24),
|
|
209
|
-
o.disabled,
|
|
210
|
-
o.borderRadius('oval'),
|
|
211
|
-
o.outline.default.focus,
|
|
212
|
-
])}
|
|
213
|
-
|
|
214
|
-
${disabledSelector} {
|
|
215
|
-
cursor: unset;
|
|
104
|
+
height: 40px;
|
|
105
|
+
background-color: ${({ theme }) => theme.color.brand};
|
|
106
|
+
color: ${({ theme }) => theme.color.text5};
|
|
107
|
+
border: none;
|
|
108
|
+
border-radius: 9999px;
|
|
109
|
+
|
|
110
|
+
:not(:disabled):active {
|
|
111
|
+
background-color: var(--charcoal-brand-press);
|
|
216
112
|
}
|
|
217
113
|
`
|
|
218
|
-
|
|
219
|
-
const TextField = styled.input.attrs({ type: 'text' })<{ assertive?: boolean }>`
|
|
220
|
-
font: inherit;
|
|
221
|
-
appearance: none;
|
|
222
|
-
border-style: none;
|
|
223
|
-
|
|
224
|
-
&:focus {
|
|
225
|
-
outline: none;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
${(p) =>
|
|
229
|
-
theme((o) => [
|
|
230
|
-
o.height.px(40),
|
|
231
|
-
o.width.column(2),
|
|
232
|
-
o.padding.horizontal(8).vertical(0),
|
|
233
|
-
o.borderRadius(4),
|
|
234
|
-
o.bg.surface3.hover,
|
|
235
|
-
o.font.text2,
|
|
236
|
-
o.typography(14).preserveHalfLeading,
|
|
237
|
-
o.disabled,
|
|
238
|
-
o.outline.default.focus,
|
|
239
|
-
p.assertive !== undefined && p.assertive && o.outline.assertive,
|
|
240
|
-
])}
|
|
241
|
-
`
|
|
242
|
-
|
|
243
|
-
const BorderedBox = styled.div`
|
|
244
|
-
${theme((o) => [
|
|
245
|
-
o.bg.background1,
|
|
246
|
-
o.font.text2,
|
|
247
|
-
o.typography(14),
|
|
248
|
-
o.width.column(4),
|
|
249
|
-
o.margin.vertical(40),
|
|
250
|
-
o.padding.all(24),
|
|
251
|
-
o.border.default,
|
|
252
|
-
o.borderRadius(8),
|
|
253
|
-
])}
|
|
254
|
-
`
|
|
255
|
-
|
|
256
|
-
const GradientBox = styled.div`
|
|
257
|
-
${theme((o) => [
|
|
258
|
-
o.bg.callToAction('to right').hover.press,
|
|
259
|
-
o.font.text5.hover.press,
|
|
260
|
-
o.width.column(2),
|
|
261
|
-
o.padding.all(40),
|
|
262
|
-
o.margin.vertical(24),
|
|
263
|
-
o.typography(20).bold,
|
|
264
|
-
o.borderRadius(8),
|
|
265
|
-
])}
|
|
266
|
-
|
|
267
|
-
text-align: center;
|
|
268
|
-
`
|
|
269
|
-
|
|
270
|
-
const WarningGradientBox = styled.div`
|
|
271
|
-
${theme((o) => [
|
|
272
|
-
o.bg.callToAction('to right').hover.press,
|
|
273
|
-
o.font.text5.hover.press,
|
|
274
|
-
o.width.column(2),
|
|
275
|
-
o.margin.vertical(24),
|
|
276
|
-
o.typography(20).bold,
|
|
277
|
-
o.borderRadius(8),
|
|
278
|
-
])}
|
|
279
|
-
/* 'padding'と'typography'を同時に指定しない場合にはtransitionが使えない */
|
|
280
|
-
${theme((o) => [o.padding.all(40)])}
|
|
281
|
-
|
|
282
|
-
text-align: center;
|
|
283
|
-
`
|
|
284
|
-
|
|
285
|
-
const FixBox = styled.div`
|
|
286
|
-
${theme((o) => [o.width.column(3), o.margin.vertical(24)])}
|
|
287
|
-
`
|
|
288
|
-
|
|
289
|
-
const FullBox = styled.div`
|
|
290
|
-
display: inline-block;
|
|
291
|
-
|
|
292
|
-
${theme((o) => [
|
|
293
|
-
o.width.full,
|
|
294
|
-
o.bg.surface4,
|
|
295
|
-
o.font.text5,
|
|
296
|
-
o.padding.all(16),
|
|
297
|
-
])}
|
|
298
|
-
`
|
|
299
|
-
|
|
300
|
-
const LocalTheme = styled.div`
|
|
301
|
-
${defineThemeVariables({ text1: '#ffff00' })}
|
|
302
|
-
|
|
303
|
-
${theme((o) => [o.bg.surface4, o.font.text1])}
|
|
304
|
-
`
|
package/src/index.test.tsx
CHANGED
|
@@ -2,9 +2,9 @@ import { light } from '@charcoal-ui/theme'
|
|
|
2
2
|
import 'jest-styled-components'
|
|
3
3
|
|
|
4
4
|
import renderer from 'react-test-renderer'
|
|
5
|
-
import { ThemeProvider } from 'styled-components'
|
|
6
|
-
import { Example
|
|
7
|
-
import { myTheme } from './storyHelper'
|
|
5
|
+
import styled, { ThemeProvider } from 'styled-components'
|
|
6
|
+
import { Example } from './index.story'
|
|
7
|
+
import { MyTheme, myTheme } from './storyHelper'
|
|
8
8
|
|
|
9
9
|
function render(children: JSX.Element) {
|
|
10
10
|
return renderer
|
|
@@ -17,8 +17,58 @@ describe('Story', () => {
|
|
|
17
17
|
test('<Example />', () => {
|
|
18
18
|
expect(render(<Example />)).toMatchSnapshot()
|
|
19
19
|
})
|
|
20
|
+
})
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
describe('ThemeUtilsTest', () => {
|
|
23
|
+
test('<ThemeUtilsTest />', () => {
|
|
24
|
+
expect(
|
|
25
|
+
render(
|
|
26
|
+
<ThemeUtilsTest>
|
|
27
|
+
<Typography12 />
|
|
28
|
+
<Typography14True />
|
|
29
|
+
<Typography16TrueTrue />
|
|
30
|
+
</ThemeUtilsTest>
|
|
31
|
+
)
|
|
32
|
+
).toMatchSnapshot()
|
|
23
33
|
})
|
|
24
34
|
})
|
|
35
|
+
|
|
36
|
+
declare module 'styled-components' {
|
|
37
|
+
export interface DefaultTheme extends MyTheme {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ThemeUtilsTest = styled.div`
|
|
41
|
+
${({ theme }) => theme.utils.margin(0)}
|
|
42
|
+
${({ theme }) => theme.utils.margin(0, 'auto')}
|
|
43
|
+
${({ theme }) => theme.utils.margin('auto', 4, 8)}
|
|
44
|
+
${({ theme }) => theme.utils.margin(0, 4, 8, 'auto')}
|
|
45
|
+
${({ theme }) => theme.utils.marginTop(0)}
|
|
46
|
+
${({ theme }) => theme.utils.marginRight(4)}
|
|
47
|
+
${({ theme }) => theme.utils.marginBottom(8)}
|
|
48
|
+
${({ theme }) => theme.utils.marginRight(16)}
|
|
49
|
+
${({ theme }) => theme.utils.padding(0)}
|
|
50
|
+
${({ theme }) => theme.utils.padding(0, 4)}
|
|
51
|
+
${({ theme }) => theme.utils.padding(0, 4, 8)}
|
|
52
|
+
${({ theme }) => theme.utils.padding(0, 4, 8, 16)}
|
|
53
|
+
${({ theme }) => theme.utils.paddingTop(0)}
|
|
54
|
+
${({ theme }) => theme.utils.paddingRight(4)}
|
|
55
|
+
${({ theme }) => theme.utils.paddingBottom(8)}
|
|
56
|
+
${({ theme }) => theme.utils.paddingRight(16)}
|
|
57
|
+
${({ theme }) => theme.utils.gap(0)}
|
|
58
|
+
${({ theme }) => theme.utils.gap(0, 4)}
|
|
59
|
+
${({ theme }) => theme.utils.rowGap(0)}
|
|
60
|
+
${({ theme }) => theme.utils.columnGap(4)}
|
|
61
|
+
${({ theme }) => theme.utils.focusVisibleFocusRingCss}
|
|
62
|
+
${({ theme }) => theme.utils.assertiveRingCss}
|
|
63
|
+
${({ theme }) => theme.utils.disabledCss}
|
|
64
|
+
`
|
|
65
|
+
|
|
66
|
+
const Typography12 = styled.div`
|
|
67
|
+
${({ theme }) => theme.utils.typography(12)}
|
|
68
|
+
`
|
|
69
|
+
const Typography14True = styled.div`
|
|
70
|
+
${({ theme }) => theme.utils.typography(14, true)}
|
|
71
|
+
`
|
|
72
|
+
const Typography16TrueTrue = styled.div`
|
|
73
|
+
${({ theme }) => theme.utils.typography(16, true, true)}
|
|
74
|
+
`
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,13 @@ const nonBlank = <T>(value: T): value is T extends Blank ? never : T =>
|
|
|
24
24
|
isPresent(value) && (value as unknown) !== false
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
+
* @deprecated
|
|
28
|
+
* 実行時のパフォーマンスが低い問題があります。
|
|
29
|
+
* ref. https://github.com/pixiv/charcoal/pull/377
|
|
30
|
+
*
|
|
31
|
+
* styled-components の theming 方法を推奨します。
|
|
32
|
+
* ref. https://styled-components.com/docs/advanced#theming
|
|
33
|
+
*
|
|
27
34
|
* `theme(o => [...])` の `theme` ユーティリティを構築する
|
|
28
35
|
*
|
|
29
36
|
* @param _styled - DEPRECATED: styled-components の `styled` そのものを渡すとそれを元に型推論ができる。が、型引数を渡す方が型推論が高速になりやすい
|
|
@@ -85,4 +92,8 @@ export type ThemeProp<T> = ({
|
|
|
85
92
|
theme: T | undefined
|
|
86
93
|
}) => CSSObject | CSSObject[]
|
|
87
94
|
|
|
88
|
-
export
|
|
95
|
+
export { focusVisibleFocusRingCss } from './styles/focusVisibleFocusRingCss'
|
|
96
|
+
export { disabledCss } from './styles/disabledCss'
|
|
97
|
+
export { assertiveRingCss } from './styles/assertiveRingCss'
|
|
98
|
+
export type { CharcoalThemeUtils } from './utils/CharcoalStyledTheme'
|
|
99
|
+
export { addThemeUtils } from './utils/addThemeUtils'
|
package/src/storyHelper.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { Material } from '@charcoal-ui/foundation'
|
|
2
2
|
import { CharcoalTheme } from '@charcoal-ui/theme'
|
|
3
|
+
import { CharcoalThemeUtils } from './utils/CharcoalStyledTheme'
|
|
4
|
+
import { addThemeUtils } from './utils/addThemeUtils'
|
|
3
5
|
|
|
4
|
-
export type MyTheme = CharcoalTheme &
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
export type MyTheme = CharcoalTheme &
|
|
7
|
+
CharcoalThemeUtils & {
|
|
8
|
+
color: {
|
|
9
|
+
mycolor: Material
|
|
10
|
+
}
|
|
7
11
|
}
|
|
8
|
-
}
|
|
9
12
|
|
|
10
13
|
export function myTheme(theme: CharcoalTheme): MyTheme {
|
|
11
14
|
return {
|
|
12
|
-
...theme,
|
|
15
|
+
...addThemeUtils(theme),
|
|
13
16
|
color: {
|
|
14
17
|
...theme.color,
|
|
15
18
|
mycolor: '#ff9e8c',
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Canvas, Meta } from '@storybook/blocks'
|
|
2
|
+
|
|
3
|
+
import * as CheckboxStories from './index.story'
|
|
4
|
+
|
|
5
|
+
<Meta title="styled/addThemeUtils" />
|
|
6
|
+
|
|
7
|
+
# Theme Utils
|
|
8
|
+
|
|
9
|
+
We offer utilities for spacing and common classes through `theme.utils`, which enable type-safe spacing.
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
You can add utilities using `addThemeUtils` by passing the object to the ThemeProvider.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
// ...
|
|
17
|
+
import { addThemeUtils } from '@charcoal-ui/styled'
|
|
18
|
+
|
|
19
|
+
const ExampleProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
|
20
|
+
const [theme] = useTheme()
|
|
21
|
+
const themeWithUtils = addThemeUtils(theme === 'dark' ? dark : light)
|
|
22
|
+
useThemeSetter()
|
|
23
|
+
return (
|
|
24
|
+
<ThemeProvider theme={themeWithUtils}>
|
|
25
|
+
{...}
|
|
26
|
+
</ThemeProvider>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
You can access the theme object using [styled theming](https://styled-components.com/docs/advanced#theming).
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
const AssertiveRingDiv = styled.div`
|
|
37
|
+
${({ theme }) => [theme.utils.assertiveRingCss, theme.utils.margin(8)]}
|
|
38
|
+
transition: 0.2s box-shadow;
|
|
39
|
+
`
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Example
|
|
43
|
+
|
|
44
|
+
<Canvas of={CheckboxStories.Example} />
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
margin,
|
|
3
|
+
marginBottom,
|
|
4
|
+
marginLeft,
|
|
5
|
+
marginRight,
|
|
6
|
+
marginTop,
|
|
7
|
+
} from './margin'
|
|
8
|
+
import {
|
|
9
|
+
padding,
|
|
10
|
+
paddingBottom,
|
|
11
|
+
paddingLeft,
|
|
12
|
+
paddingRight,
|
|
13
|
+
paddingTop,
|
|
14
|
+
} from './padding'
|
|
15
|
+
import { columnGap, gap, rowGap } from './gap'
|
|
16
|
+
import { disabledCss } from '../styles/disabledCss'
|
|
17
|
+
import { typography } from './typographyCss'
|
|
18
|
+
import { focusVisibleFocusRingCss } from '../styles/focusVisibleFocusRingCss'
|
|
19
|
+
import { assertiveRingCss } from '../styles/assertiveRingCss'
|
|
20
|
+
|
|
21
|
+
export type CharcoalThemeUtils = {
|
|
22
|
+
utils: {
|
|
23
|
+
margin: typeof margin
|
|
24
|
+
marginTop: typeof marginTop
|
|
25
|
+
marginLeft: typeof marginLeft
|
|
26
|
+
marginBottom: typeof marginBottom
|
|
27
|
+
marginRight: typeof marginRight
|
|
28
|
+
padding: typeof padding
|
|
29
|
+
paddingTop: typeof paddingTop
|
|
30
|
+
paddingLeft: typeof paddingLeft
|
|
31
|
+
paddingBottom: typeof paddingBottom
|
|
32
|
+
paddingRight: typeof paddingRight
|
|
33
|
+
gap: typeof gap
|
|
34
|
+
rowGap: typeof rowGap
|
|
35
|
+
columnGap: typeof columnGap
|
|
36
|
+
typography: typeof typography
|
|
37
|
+
/**
|
|
38
|
+
* Generally use with `transition: 0.2s box-shadow`.
|
|
39
|
+
*/
|
|
40
|
+
focusVisibleFocusRingCss: typeof focusVisibleFocusRingCss
|
|
41
|
+
/**
|
|
42
|
+
* Generally use with `transition: 0.2s box-shadow`.
|
|
43
|
+
*/
|
|
44
|
+
assertiveRingCss: typeof assertiveRingCss
|
|
45
|
+
disabledCss: typeof disabledCss
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CharcoalTheme } from '@charcoal-ui/theme'
|
|
2
|
+
import { CharcoalThemeUtils } from './CharcoalStyledTheme'
|
|
3
|
+
import {
|
|
4
|
+
margin,
|
|
5
|
+
marginBottom,
|
|
6
|
+
marginLeft,
|
|
7
|
+
marginRight,
|
|
8
|
+
marginTop,
|
|
9
|
+
} from './margin'
|
|
10
|
+
import {
|
|
11
|
+
padding,
|
|
12
|
+
paddingBottom,
|
|
13
|
+
paddingLeft,
|
|
14
|
+
paddingRight,
|
|
15
|
+
paddingTop,
|
|
16
|
+
} from './padding'
|
|
17
|
+
import { columnGap, gap, rowGap } from './gap'
|
|
18
|
+
import { disabledCss } from '../styles/disabledCss'
|
|
19
|
+
import { typography } from './typographyCss'
|
|
20
|
+
import { focusVisibleFocusRingCss } from '../styles/focusVisibleFocusRingCss'
|
|
21
|
+
import { assertiveRingCss } from '../styles/assertiveRingCss'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adds some utilities to the theme object.
|
|
25
|
+
* They can be used as an alternative `createTheme`(`theme(o=>)`) for styling.
|
|
26
|
+
*/
|
|
27
|
+
export function addThemeUtils(
|
|
28
|
+
theme: CharcoalTheme
|
|
29
|
+
): CharcoalTheme & CharcoalThemeUtils {
|
|
30
|
+
return {
|
|
31
|
+
...theme,
|
|
32
|
+
utils: {
|
|
33
|
+
margin,
|
|
34
|
+
marginTop,
|
|
35
|
+
marginLeft,
|
|
36
|
+
marginBottom,
|
|
37
|
+
marginRight,
|
|
38
|
+
padding,
|
|
39
|
+
paddingTop,
|
|
40
|
+
paddingLeft,
|
|
41
|
+
paddingBottom,
|
|
42
|
+
paddingRight,
|
|
43
|
+
gap,
|
|
44
|
+
rowGap,
|
|
45
|
+
columnGap,
|
|
46
|
+
typography,
|
|
47
|
+
focusVisibleFocusRingCss,
|
|
48
|
+
assertiveRingCss,
|
|
49
|
+
disabledCss,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
}
|