Skip to content

Commit c78e5fd

Browse files
saitolumeclaude
andauthored
fix: twMergeConfigの副作用がランタイムで実行されない問題を修正 (#6254)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2556f65 commit c78e5fd

6 files changed

Lines changed: 69 additions & 61 deletions

File tree

packages/smarthr-ui/.storybook/preview.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import ReactGA from 'react-ga4'
1111
import { INITIAL_VIEWPORTS } from 'storybook/viewport'
1212
import resolveConfig from 'tailwindcss/resolveConfig'
1313

14+
// twMergeConfig を最初に設定する(他のモジュールの tv() より先に実行する必要がある)
15+
// eslint-disable-next-line smarthr/require-barrel-import
16+
import '../src/configureTwMerge'
1417
// eslint-disable-next-line smarthr/require-barrel-import
1518
import '../src/styles/index.css'
1619
import { EnvironmentProvider, IntlProvider, locales } from '../src'

packages/smarthr-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@
170170
"scaffold:storybook": "plop"
171171
},
172172
"sideEffects": [
173-
"*.css"
173+
"*.css",
174+
"**/configureTwMerge.*"
174175
],
175176
"typings": "lib/index.d.ts"
176177
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { validators } from 'tailwind-merge'
2+
import { defaultConfig } from 'tailwind-variants'
3+
4+
import { defaultWidth } from './themes'
5+
6+
const DEFAULT_WIDTH_KEYS = Object.keys(defaultWidth) as Array<keyof typeof defaultWidth>
7+
8+
defaultConfig.twMergeConfig = {
9+
prefix: 'shr-',
10+
classGroups: {
11+
w: [{ w: [...DEFAULT_WIDTH_KEYS, validators.isArbitraryValue] }],
12+
basis: [{ basis: [...DEFAULT_WIDTH_KEYS, validators.isArbitraryValue] }],
13+
boxShadow: [
14+
{
15+
shadow: [
16+
'layer-0',
17+
'layer-1',
18+
'layer-2',
19+
'layer-3',
20+
'layer-4',
21+
'outline',
22+
'underline',
23+
'input-hover',
24+
'none',
25+
],
26+
},
27+
],
28+
'border-shorthand': [
29+
'border-shorthand',
30+
'border-t-shorthand',
31+
'border-r-shorthand',
32+
'border-b-shorthand',
33+
'border-l-shorthand',
34+
],
35+
fontSize: [
36+
{
37+
text: ['2xs', 'xs', 'sm', 'base', 'lg', 'xl', '2xl', 'inherit'],
38+
},
39+
],
40+
lineHeight: [
41+
{
42+
leading: ['none', 'tight', 'normal', 'loose', '[0]'],
43+
},
44+
],
45+
zIndex: [
46+
{
47+
z: [
48+
'auto',
49+
'0',
50+
'1',
51+
'fixed-menu',
52+
'overlap-base',
53+
'overlap',
54+
(classPart: string) => /^\[\d+\]$/.test(classPart),
55+
],
56+
},
57+
],
58+
focus: ['focus-indicator', 'focus-indicator--outer', 'focus-indicator-none'],
59+
},
60+
}

packages/smarthr-ui/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './configureTwMerge'
2+
13
// components
24
export { DisclosureTrigger, DisclosureContent } from './components/Disclosure'
35
export { Balloon } from './components/Balloon'

packages/smarthr-ui/src/smarthr-ui-preset.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { tv } from 'tailwind-variants'
22

3-
// smarthr-ui-presetをimportして設定を適用
4-
import './smarthr-ui-preset'
3+
// configureTwMergeをimportして設定を適用
4+
import './configureTwMerge'
55

66
describe('twMergeConfig', () => {
77
describe('classGroups', () => {

packages/smarthr-ui/src/smarthr-ui-preset.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { darken } from 'polished'
2-
import { validators } from 'tailwind-merge'
3-
import { defaultConfig } from 'tailwind-variants'
42
import plugin from 'tailwindcss/plugin'
53

64
import {
@@ -16,62 +14,6 @@ import {
1614

1715
import type { Config } from 'tailwindcss'
1816

19-
const DEFAULT_WIDTH_KEYS = Object.keys(defaultWidth) as Array<keyof typeof defaultWidth>
20-
21-
defaultConfig.twMergeConfig = {
22-
prefix: 'shr-',
23-
classGroups: {
24-
w: [{ w: [...DEFAULT_WIDTH_KEYS, validators.isArbitraryValue] }],
25-
basis: [{ basis: [...DEFAULT_WIDTH_KEYS, validators.isArbitraryValue] }],
26-
boxShadow: [
27-
{
28-
shadow: [
29-
'layer-0',
30-
'layer-1',
31-
'layer-2',
32-
'layer-3',
33-
'layer-4',
34-
'outline',
35-
'underline',
36-
'input-hover',
37-
'none',
38-
],
39-
},
40-
],
41-
'border-shorthand': [
42-
'border-shorthand',
43-
'border-t-shorthand',
44-
'border-r-shorthand',
45-
'border-b-shorthand',
46-
'border-l-shorthand',
47-
],
48-
fontSize: [
49-
{
50-
text: ['2xs', 'xs', 'sm', 'base', 'lg', 'xl', '2xl', 'inherit'],
51-
},
52-
],
53-
lineHeight: [
54-
{
55-
leading: ['none', 'tight', 'normal', 'loose', '[0]'],
56-
},
57-
],
58-
zIndex: [
59-
{
60-
z: [
61-
'auto',
62-
'0',
63-
'1',
64-
'fixed-menu',
65-
'overlap-base',
66-
'overlap',
67-
(classPart: string) => /^\[\d+\]$/.test(classPart),
68-
],
69-
},
70-
],
71-
focus: ['focus-indicator', 'focus-indicator--outer', 'focus-indicator-none'],
72-
},
73-
}
74-
7517
const spacingByChar = createSpacingByChar(defaultHtmlFontSize / 2)
7618
type Spacing = {
7719
[key in (typeof spacingSizes)[number]]: string

0 commit comments

Comments
 (0)