@docsplain-kit/core 0.0.56 → 0.0.57
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 +36 -0
- package/div/div.js +20 -2
- package/div/div.js.map +1 -1
- package/div/div.props.d.ts +2 -0
- package/package.json +1 -1
- package/withUiKit.js +209 -58
package/README.md
CHANGED
|
@@ -62,3 +62,39 @@ export default function Page() {
|
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
📖 **See [SERVER_COMPONENTS.md](./SERVER_COMPONENTS.md) for a complete guide** with examples, best practices, and troubleshooting.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 🎨 **Theme-Aware Div Colors**
|
|
69
|
+
|
|
70
|
+
`Div` supports `bgColor` and `borderColor` props. Pass Tailwind color tokens without the utility prefix:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
<Div bgColor="control-50" borderColor="control-200" />
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The dark-mode color is generated by `withUiKit`. Numeric shades reverse automatically, so `control-50` becomes `control-950`.
|
|
77
|
+
|
|
78
|
+
You can override any reverse color from `tailwind.config.js`:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
const withUiKit = require('@docsplain-kit/core/withUiKit');
|
|
82
|
+
|
|
83
|
+
module.exports = withUiKit({
|
|
84
|
+
content: ['./src/**/*.{js,ts,jsx,tsx}'],
|
|
85
|
+
theme: { extend: {} },
|
|
86
|
+
plugins: [],
|
|
87
|
+
uiKit: {
|
|
88
|
+
reverseColors: {
|
|
89
|
+
bg: {
|
|
90
|
+
white: 'control-800',
|
|
91
|
+
},
|
|
92
|
+
border: {
|
|
93
|
+
white: 'control-700',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Use a top-level key such as `white: 'control-800'` when the same reverse color should apply to both `bgColor` and `borderColor`.
|
package/div/div.js
CHANGED
|
@@ -5,9 +5,27 @@ exports.Div = void 0;
|
|
|
5
5
|
var tslib_1 = require("tslib");
|
|
6
6
|
var react_1 = tslib_1.__importStar(require("react"));
|
|
7
7
|
var tailwind_merge_config_1 = require("../tailwind-merge-config");
|
|
8
|
+
var normalizeColorToken = function (color) {
|
|
9
|
+
if (!color) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return color
|
|
13
|
+
.trim()
|
|
14
|
+
.replace(/^!?(bg|border)-/, '')
|
|
15
|
+
.replace(/\./g, '-');
|
|
16
|
+
};
|
|
17
|
+
var getColorClass = function (type, color) {
|
|
18
|
+
var colorToken = normalizeColorToken(color);
|
|
19
|
+
if (!colorToken) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return type === 'bg'
|
|
23
|
+
? "bg-[var(--dpc-bg-color)] dpc-bg-".concat(colorToken)
|
|
24
|
+
: "border-[var(--dpc-border-color)] dpc-border-".concat(colorToken);
|
|
25
|
+
};
|
|
8
26
|
exports.Div = (0, react_1.forwardRef)(function Div(props, ref) {
|
|
9
|
-
var children = props.children, style = props.style, onClick = props.onClick, dangerouslySetInnerHTML = props.dangerouslySetInnerHTML, dataTestId = props.dataTestId, role = props.role, className = props.className, id = props.id, onMouseOver = props.onMouseOver, onMouseLeave = props.onMouseLeave, rest = tslib_1.__rest(props, ["children", "style", "onClick", "dangerouslySetInnerHTML", "dataTestId", "role", "className", "id", "onMouseOver", "onMouseLeave"]);
|
|
10
|
-
return (react_1["default"].createElement("div", tslib_1.__assign({ "data-testid": dataTestId, id: id, role: role, className: (0, tailwind_merge_config_1.twMerge)(
|
|
27
|
+
var children = props.children, style = props.style, onClick = props.onClick, dangerouslySetInnerHTML = props.dangerouslySetInnerHTML, dataTestId = props.dataTestId, role = props.role, className = props.className, id = props.id, onMouseOver = props.onMouseOver, onMouseLeave = props.onMouseLeave, bgColor = props.bgColor, borderColor = props.borderColor, rest = tslib_1.__rest(props, ["children", "style", "onClick", "dangerouslySetInnerHTML", "dataTestId", "role", "className", "id", "onMouseOver", "onMouseLeave", "bgColor", "borderColor"]);
|
|
28
|
+
return (react_1["default"].createElement("div", tslib_1.__assign({ "data-testid": dataTestId, id: id, role: role, className: (0, tailwind_merge_config_1.twMerge)('flex flex-row', getColorClass('bg', bgColor), getColorClass('border', borderColor), className), dangerouslySetInnerHTML: dangerouslySetInnerHTML, onClick: onClick, style: style, ref: ref, onMouseOver: onMouseOver, onMouseLeave: onMouseLeave }, rest), children));
|
|
11
29
|
});
|
|
12
30
|
exports["default"] = exports.Div;
|
|
13
31
|
//# sourceMappingURL=div.js.map
|
package/div/div.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"div.js","sourceRoot":"","sources":["../../div/div.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,qDAA0C;AAE1C,kEAAmD;
|
|
1
|
+
{"version":3,"file":"div.js","sourceRoot":"","sources":["../../div/div.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,qDAA0C;AAE1C,kEAAmD;AAEnD,IAAM,mBAAmB,GAAG,UAAC,KAAc;IACzC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,KAAK;SACT,IAAI,EAAE;SACN,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF,IAAM,aAAa,GAAG,UAAC,IAAqB,EAAE,KAAc;IAC1D,IAAM,UAAU,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAE9C,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,IAAI,KAAK,IAAI;QAClB,CAAC,CAAC,0CAAmC,UAAU,CAAE;QACjD,CAAC,CAAC,sDAA+C,UAAU,CAAE,CAAC;AAClE,CAAC,CAAC;AAEW,QAAA,GAAG,GAAG,IAAA,kBAAU,EAAgB,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG;IAC1D,IAAA,QAAQ,GAAyI,KAAK,SAA9I,EAAE,KAAK,GAAkI,KAAK,MAAvI,EAAE,OAAO,GAAyH,KAAK,QAA9H,EAAE,uBAAuB,GAAgG,KAAK,wBAArG,EAAE,UAAU,GAAoF,KAAK,WAAzF,EAAE,IAAI,GAA8E,KAAK,KAAnF,EAAE,SAAS,GAAmE,KAAK,UAAxE,EAAE,EAAE,GAA+D,KAAK,GAApE,EAAE,WAAW,GAAkD,KAAK,YAAvD,EAAE,YAAY,GAAoC,KAAK,aAAzC,EAAE,OAAO,GAA2B,KAAK,QAAhC,EAAE,WAAW,GAAc,KAAK,YAAnB,EAAK,IAAI,kBAAK,KAAK,EAAxJ,6JAAgJ,CAAF,CAAW;IAE/J,OAAO,CACL,0EACe,UAAU,EACvB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,IAAA,+BAAO,EAChB,eAAe,EACf,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,EAC5B,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,EACpC,SAAS,CACV,EACD,uBAAuB,EAAE,uBAAuB,EAChD,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,IACtB,IAAI,GAEP,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAe,WAAG,CAAC"}
|
package/div/div.props.d.ts
CHANGED
package/package.json
CHANGED
package/withUiKit.js
CHANGED
|
@@ -10,15 +10,209 @@ const { lineHeights } = require('./config/typography/line-heights');
|
|
|
10
10
|
const { fontFamily } = require('./config/typography/font-family');
|
|
11
11
|
const { widthHeight } = require('./config/width-height');
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const DEFAULT_REVERSE_COLOR_SHADES = {
|
|
14
|
+
50: '950',
|
|
15
|
+
100: '900',
|
|
16
|
+
200: '800',
|
|
17
|
+
300: '700',
|
|
18
|
+
400: '600',
|
|
19
|
+
500: '500',
|
|
20
|
+
600: '400',
|
|
21
|
+
700: '300',
|
|
22
|
+
800: '200',
|
|
23
|
+
900: '100',
|
|
24
|
+
950: '50',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const DEPRECATED_TAILWIND_COLOR_KEYS = ['lightBlue', 'warmGray', 'trueGray', 'coolGray', 'blueGray'];
|
|
28
|
+
|
|
29
|
+
const UI_KIT_COLORS = {
|
|
30
|
+
'transparent': 'transparent',
|
|
31
|
+
'white': '#FFFFFF',
|
|
32
|
+
'black': '#000000',
|
|
33
|
+
'primary': {
|
|
34
|
+
...primary,
|
|
35
|
+
light: primary['300'],
|
|
36
|
+
DEFAULT: primary['500'],
|
|
37
|
+
dark: primary['700'],
|
|
38
|
+
},
|
|
39
|
+
'secondary': {
|
|
40
|
+
...secondary,
|
|
41
|
+
light: secondary['300'],
|
|
42
|
+
DEFAULT: secondary['500'],
|
|
43
|
+
dark: secondary['700'],
|
|
44
|
+
},
|
|
45
|
+
'info': {
|
|
46
|
+
...info,
|
|
47
|
+
light: info['300'],
|
|
48
|
+
DEFAULT: info['500'],
|
|
49
|
+
dark: info['700'],
|
|
50
|
+
},
|
|
51
|
+
'success': {
|
|
52
|
+
...success,
|
|
53
|
+
light: success['300'],
|
|
54
|
+
DEFAULT: success['500'],
|
|
55
|
+
dark: success['700'],
|
|
56
|
+
},
|
|
57
|
+
'warning': {
|
|
58
|
+
...warning,
|
|
59
|
+
light: warning['300'],
|
|
60
|
+
DEFAULT: warning['500'],
|
|
61
|
+
dark: warning['700'],
|
|
62
|
+
},
|
|
63
|
+
'danger': {
|
|
64
|
+
...danger,
|
|
65
|
+
light: danger['300'],
|
|
66
|
+
DEFAULT: danger['500'],
|
|
67
|
+
dark: danger['700'],
|
|
68
|
+
},
|
|
69
|
+
'control': {
|
|
70
|
+
...control,
|
|
71
|
+
light: control['300'],
|
|
72
|
+
DEFAULT: control['500'],
|
|
73
|
+
dark: control['700'],
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const normalizeColorToken = (color) => {
|
|
78
|
+
if (typeof color !== 'string') {
|
|
79
|
+
return color;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return color
|
|
83
|
+
.trim()
|
|
84
|
+
.replace(/^!?(bg|border)-/, '')
|
|
85
|
+
.replace(/\./g, '-');
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const flattenColorPalette = (colors, prefix = '') => {
|
|
89
|
+
return Object.keys(colors || {}).reduce((result, key) => {
|
|
90
|
+
if (DEPRECATED_TAILWIND_COLOR_KEYS.includes(key)) {
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const value = colors[key];
|
|
95
|
+
|
|
96
|
+
if (typeof value === 'string') {
|
|
97
|
+
const colorKey = key === 'DEFAULT' ? prefix : [prefix, key].filter(Boolean).join('-');
|
|
98
|
+
|
|
99
|
+
if (colorKey) {
|
|
100
|
+
result[colorKey] = value;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
107
|
+
return Object.assign(result, flattenColorPalette(value, [prefix, key].filter(Boolean).join('-')));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
}, {});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const getReverseColorToken = (token, type, reverseColors, colorMap) => {
|
|
115
|
+
const typeReverseColors = reverseColors && reverseColors[type];
|
|
116
|
+
const configuredReverseColor = (
|
|
117
|
+
typeReverseColors && typeReverseColors[token]
|
|
118
|
+
) || (reverseColors && reverseColors[token]);
|
|
119
|
+
|
|
120
|
+
if (configuredReverseColor) {
|
|
121
|
+
return normalizeColorToken(configuredReverseColor);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (token === 'white') {
|
|
125
|
+
return 'black';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (token === 'black') {
|
|
129
|
+
return 'white';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const shadeMatch = token.match(/^(.*)-(\d{2,3})$/);
|
|
133
|
+
|
|
134
|
+
if (!shadeMatch) {
|
|
135
|
+
return token;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const [, colorName, shade] = shadeMatch;
|
|
139
|
+
const reverseShade = DEFAULT_REVERSE_COLOR_SHADES[shade];
|
|
140
|
+
const reverseToken = `${colorName}-${reverseShade}`;
|
|
141
|
+
|
|
142
|
+
return colorMap[reverseToken] ? reverseToken : token;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const createThemedColorUtilities = (reverseColors = {}) => {
|
|
146
|
+
return ({ addUtilities, theme, e }) => {
|
|
147
|
+
const colorMap = flattenColorPalette(theme('colors') || {});
|
|
148
|
+
const utilities = {};
|
|
149
|
+
|
|
150
|
+
Object.entries(colorMap).forEach(([token, value]) => {
|
|
151
|
+
const bgClassName = e(`dpc-bg-${token}`);
|
|
152
|
+
const borderClassName = e(`dpc-border-${token}`);
|
|
153
|
+
const reverseBgToken = getReverseColorToken(token, 'bg', reverseColors, colorMap);
|
|
154
|
+
const reverseBorderToken = getReverseColorToken(token, 'border', reverseColors, colorMap);
|
|
155
|
+
const reverseBgValue = colorMap[reverseBgToken] || value;
|
|
156
|
+
const reverseBorderValue = colorMap[reverseBorderToken] || value;
|
|
157
|
+
|
|
158
|
+
utilities[`.${bgClassName}`] = {
|
|
159
|
+
'--dpc-bg-color': value,
|
|
160
|
+
};
|
|
161
|
+
utilities[`.dark .${bgClassName}, [data-theme="dark"] .${bgClassName}, .${bgClassName}.dark, .${bgClassName}[data-theme="dark"]`] = {
|
|
162
|
+
'--dpc-bg-color': reverseBgValue,
|
|
163
|
+
};
|
|
164
|
+
utilities[`.${borderClassName}`] = {
|
|
165
|
+
'--dpc-border-color': value,
|
|
166
|
+
};
|
|
167
|
+
utilities[`.dark .${borderClassName}, [data-theme="dark"] .${borderClassName}, .${borderClassName}.dark, .${borderClassName}[data-theme="dark"]`] = {
|
|
168
|
+
'--dpc-border-color': reverseBorderValue,
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
addUtilities(utilities);
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const getThemedColorSafelist = (tailwindConfig) => {
|
|
177
|
+
const tailwindTheme = tailwindConfig.theme || {};
|
|
178
|
+
const tailwindExtend = tailwindTheme.extend || {};
|
|
179
|
+
let tailwindDefaultColors = {};
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
tailwindDefaultColors = require('tailwindcss/colors');
|
|
183
|
+
} catch {
|
|
184
|
+
tailwindDefaultColors = {};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const configuredColors = Object.assign(
|
|
188
|
+
{},
|
|
189
|
+
tailwindDefaultColors,
|
|
190
|
+
UI_KIT_COLORS,
|
|
191
|
+
tailwindTheme.colors || {},
|
|
192
|
+
tailwindExtend.colors || {},
|
|
193
|
+
);
|
|
194
|
+
const colorTokens = Object.keys(flattenColorPalette(configuredColors));
|
|
195
|
+
|
|
196
|
+
return colorTokens.flatMap((token) => [`dpc-bg-${token}`, `dpc-border-${token}`]);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const withUiKit = (tailwindConfig = {}) => {
|
|
200
|
+
const theme = tailwindConfig.theme || {};
|
|
201
|
+
const themeExtend = theme.extend || {};
|
|
202
|
+
const uiKit = tailwindConfig.uiKit || {};
|
|
203
|
+
|
|
14
204
|
return {
|
|
15
205
|
darkMode: 'selector',
|
|
206
|
+
safelist: [
|
|
207
|
+
...(tailwindConfig.safelist || []),
|
|
208
|
+
...getThemedColorSafelist(tailwindConfig),
|
|
209
|
+
],
|
|
16
210
|
content: [
|
|
17
211
|
'./node_modules/@docsplain-kit/core/**/*',
|
|
18
|
-
...tailwindConfig.content,
|
|
212
|
+
...(tailwindConfig.content || []),
|
|
19
213
|
],
|
|
20
214
|
theme: {
|
|
21
|
-
...
|
|
215
|
+
...theme,
|
|
22
216
|
screens: {
|
|
23
217
|
'sm': '640px',
|
|
24
218
|
'md': '1024px',
|
|
@@ -34,87 +228,44 @@ const withUiKit = (tailwindConfig) => {
|
|
|
34
228
|
'gt-xs': { 'min': '640px' },
|
|
35
229
|
'gt-sm': { 'min': '1024px' },
|
|
36
230
|
'gt-md': { 'min': '1200px' },
|
|
37
|
-
...
|
|
231
|
+
...theme.screens,
|
|
38
232
|
},
|
|
39
233
|
fontSize: {
|
|
40
234
|
...fontSizes,
|
|
41
|
-
...
|
|
235
|
+
...theme.fontSize,
|
|
42
236
|
},
|
|
43
237
|
fontFamily: {
|
|
44
238
|
...fontFamily,
|
|
45
|
-
...
|
|
239
|
+
...theme.fontFamily,
|
|
46
240
|
},
|
|
47
241
|
lineHeight: {
|
|
48
242
|
...lineHeights,
|
|
49
|
-
...
|
|
243
|
+
...theme.lineHeight,
|
|
50
244
|
},
|
|
51
245
|
minWidth: {
|
|
52
246
|
...widthHeight,
|
|
53
|
-
...
|
|
247
|
+
...theme.minWidth,
|
|
54
248
|
},
|
|
55
249
|
minHeight: {
|
|
56
250
|
...widthHeight,
|
|
57
|
-
...
|
|
251
|
+
...theme.minHeight,
|
|
58
252
|
},
|
|
59
253
|
extend: {
|
|
60
|
-
...
|
|
61
|
-
colors: Object.assign({},
|
|
62
|
-
'transparent': 'transparent',
|
|
63
|
-
'white': '#FFFFFF',
|
|
64
|
-
'black': '#000000',
|
|
65
|
-
'primary': {
|
|
66
|
-
...primary,
|
|
67
|
-
light: primary['300'],
|
|
68
|
-
DEFAULT: primary['500'],
|
|
69
|
-
dark: primary['700'],
|
|
70
|
-
},
|
|
71
|
-
'secondary': {
|
|
72
|
-
...secondary,
|
|
73
|
-
light: secondary['300'],
|
|
74
|
-
DEFAULT: secondary['500'],
|
|
75
|
-
dark: secondary['700'],
|
|
76
|
-
},
|
|
77
|
-
'info': {
|
|
78
|
-
...info,
|
|
79
|
-
light: info['300'],
|
|
80
|
-
DEFAULT: info['500'],
|
|
81
|
-
dark: info['700'],
|
|
82
|
-
},
|
|
83
|
-
'success': {
|
|
84
|
-
...success,
|
|
85
|
-
light: success['300'],
|
|
86
|
-
DEFAULT: success['500'],
|
|
87
|
-
dark: success['700'],
|
|
88
|
-
},
|
|
89
|
-
'warning': {
|
|
90
|
-
...warning,
|
|
91
|
-
light: warning['300'],
|
|
92
|
-
DEFAULT: warning['500'],
|
|
93
|
-
dark: warning['700'],
|
|
94
|
-
},
|
|
95
|
-
'danger': {
|
|
96
|
-
...danger,
|
|
97
|
-
light: danger['300'],
|
|
98
|
-
DEFAULT: danger['500'],
|
|
99
|
-
dark: danger['700'],
|
|
100
|
-
},
|
|
101
|
-
'control': {
|
|
102
|
-
...control,
|
|
103
|
-
light: control['300'],
|
|
104
|
-
DEFAULT: control['500'],
|
|
105
|
-
dark: control['700'],
|
|
106
|
-
},
|
|
107
|
-
}, tailwindConfig.theme.extend.colors),
|
|
254
|
+
...themeExtend,
|
|
255
|
+
colors: Object.assign({}, UI_KIT_COLORS, themeExtend.colors),
|
|
108
256
|
height: {
|
|
109
257
|
'dvh': '100dvh',
|
|
258
|
+
...themeExtend.height,
|
|
110
259
|
},
|
|
111
260
|
direction: {
|
|
112
261
|
'inherit': 'inherit',
|
|
262
|
+
...themeExtend.direction,
|
|
113
263
|
},
|
|
114
264
|
},
|
|
115
265
|
},
|
|
116
266
|
plugins: [
|
|
117
|
-
|
|
267
|
+
createThemedColorUtilities(uiKit.reverseColors || {}),
|
|
268
|
+
...(tailwindConfig.plugins || []),
|
|
118
269
|
],
|
|
119
270
|
};
|
|
120
271
|
};
|