@docsplain-kit/core 0.0.55 → 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/label/label.js +11 -4
- package/label/label.js.map +1 -1
- package/label/label.props.d.ts +1 -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/label/label.js
CHANGED
|
@@ -19,18 +19,25 @@ catch (_a) {
|
|
|
19
19
|
// Provider not available, use default
|
|
20
20
|
}
|
|
21
21
|
var Label = function (props) {
|
|
22
|
-
var className = props.className, label = props.label, children = props.children, containerRef = props.containerRef, disabled = props.disabled, _a = props.required, required = _a === void 0 ? false : _a, textProps = props.textProps, _b = props.orientation, orientation = _b === void 0 ? 'vertical' : _b, moreInfo = props.moreInfo, _c = props.validationState, validationState = _c === void 0 ? 'none' : _c, validationMessage = props.validationMessage, wrapperClassName = props.wrapperClassName;
|
|
23
|
-
var
|
|
22
|
+
var className = props.className, label = props.label, children = props.children, containerRef = props.containerRef, disabled = props.disabled, _a = props.required, required = _a === void 0 ? false : _a, textProps = props.textProps, _b = props.orientation, orientation = _b === void 0 ? 'vertical' : _b, moreInfo = props.moreInfo, _c = props.validationState, validationState = _c === void 0 ? 'none' : _c, validationMessage = props.validationMessage, wrapperClassName = props.wrapperClassName, _d = props.variant, variant = _d === void 0 ? 'label' : _d;
|
|
23
|
+
var _e = (0, react_1.useState)(false), show = _e[0], setShow = _e[1];
|
|
24
|
+
var Component = variant;
|
|
25
|
+
var componentProps = {};
|
|
26
|
+
if (variant === 'label') {
|
|
27
|
+
Object.assign(componentProps, {
|
|
28
|
+
ref: { containerRef: containerRef }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
24
31
|
// Try to get theme from provider, fallback to 'light'
|
|
25
32
|
var theme = 'light';
|
|
26
33
|
try {
|
|
27
34
|
theme = useThemeSafe();
|
|
28
35
|
}
|
|
29
|
-
catch (
|
|
36
|
+
catch (_f) {
|
|
30
37
|
// Not in provider, use default
|
|
31
38
|
}
|
|
32
39
|
return (react_1["default"].createElement(div_1["default"], { className: (0, tailwind_merge_config_1.twMerge)('flex-col w-full gap-y-0.5', wrapperClassName) },
|
|
33
|
-
react_1["default"].createElement(
|
|
40
|
+
react_1["default"].createElement(Component, tslib_1.__assign({ className: (0, tailwind_merge_config_1.twMerge)('w-fit flex justify-center gap-1.5', orientation === 'vertical' ? 'flex-col' : 'flex-row', disabled ? 'cursor-not-allowed' : 'cursor-pointer', className) }, componentProps),
|
|
34
41
|
react_1["default"].createElement(div_1["default"], { className: 'items-center gap-x-1' },
|
|
35
42
|
react_1["default"].createElement(text_1["default"], tslib_1.__assign({ align: 'start', type: 'medium', disabled: disabled, typography: (textProps === null || textProps === void 0 ? void 0 : textProps.typography) || 'sm' }, textProps),
|
|
36
43
|
label,
|
package/label/label.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label.js","sourceRoot":"","sources":["../../label/label.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,qDAAwC;AAExC,yDAA2B;AAC3B,kEAAmD;AACnD,uDAAyB;AACzB,uEAAwC;AACxC,6CAIuB;AAEvB,yDAAyD;AACzD,IAAI,YAAY,GAA2B,cAAM,OAAA,OAAO,EAAP,CAAO,CAAC;AACzD,IAAI;IACM,IAAA,QAAQ,GAAK,OAAO,CAAC,aAAa,CAAC,SAA3B,CAA4B;IAC5C,YAAY,GAAG,QAAQ,CAAC;CACzB;AAAC,WAAM;IACN,sCAAsC;CACvC;AAEM,IAAM,KAAK,GAAG,UAAC,KAAiB;IAEnC,IAAA,SAAS,
|
|
1
|
+
{"version":3,"file":"label.js","sourceRoot":"","sources":["../../label/label.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,qDAAwC;AAExC,yDAA2B;AAC3B,kEAAmD;AACnD,uDAAyB;AACzB,uEAAwC;AACxC,6CAIuB;AAEvB,yDAAyD;AACzD,IAAI,YAAY,GAA2B,cAAM,OAAA,OAAO,EAAP,CAAO,CAAC;AACzD,IAAI;IACM,IAAA,QAAQ,GAAK,OAAO,CAAC,aAAa,CAAC,SAA3B,CAA4B;IAC5C,YAAY,GAAG,QAAQ,CAAC;CACzB;AAAC,WAAM;IACN,sCAAsC;CACvC;AAEM,IAAM,KAAK,GAAG,UAAC,KAAiB;IAEnC,IAAA,SAAS,GAaP,KAAK,UAbE,EACT,KAAK,GAYH,KAAK,MAZF,EACL,QAAQ,GAWN,KAAK,SAXC,EACR,YAAY,GAUV,KAAK,aAVK,EACZ,QAAQ,GASN,KAAK,SATC,EACR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tN,2CAAM,QAAQ,EAAC,SAAS,EAAC,QAAQ,EAAC,SAAS,EACzC,CAAC,EAAC,69CAA69C,EAC/9C,IAAI,EAAC,cAAc,GAAE;YACvB,2CAAM,CAAC,EAAC,wIAAwI,EAAC,IAAI,EAAC,cAAc,GAAE,CAClK,CACP,CAAC;KACH;IAED,OAAO,CACL,0CAAK,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,OAAO,EAAC,WAAW,EAAC,SAAS,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAC,MAAM,EAAC,KAAK,EAAC,4BAA4B;QAClK,2CAAM,CAAC,EAAC,yHAAyH,EAAC,IAAI,EAAC,cAAc,GAAE;QACvJ,2CAAM,CAAC,EAAC,gKAAgK,EAAC,IAAI,EAAC,cAAc,GAAE;QAC9L,2CAAM,QAAQ,EAAC,SAAS,EAAC,QAAQ,EAAC,SAAS,EAAC,CAAC,EAAC,gTAAgT,EAAC,IAAI,EAAC,cAAc,GAAE,CAChX,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,qBAAe,aAAK,CAAC"}
|
package/label/label.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
|
};
|