@nextui-org/system-rsc
Advanced tools
Comparing version 0.0.0-dev-v2-20230916212336 to 0.0.0-dev-v2-20231103142249
@@ -92,35 +92,28 @@ "use strict"; | ||
var COMMON_UNITS = ["small", "medium", "large"]; | ||
var tv = (options, config) => { | ||
var _a, _b, _c; | ||
return (0, import_tailwind_variants.tv)(options, { | ||
...config, | ||
twMerge: (_a = config == null ? void 0 : config.twMerge) != null ? _a : true, | ||
twMergeConfig: { | ||
...config == null ? void 0 : config.twMergeConfig, | ||
theme: { | ||
...(_b = config == null ? void 0 : config.twMergeConfig) == null ? void 0 : _b.theme, | ||
opacity: ["disabled"], | ||
spacing: ["divider", "unit", ...mappedSpacingScaleKeys], | ||
borderWidth: COMMON_UNITS, | ||
borderRadius: COMMON_UNITS | ||
}, | ||
classGroups: { | ||
...(_c = config == null ? void 0 : config.twMergeConfig) == null ? void 0 : _c.classGroups, | ||
shadow: [{ shadow: COMMON_UNITS }], | ||
"font-size": [{ text: ["tiny", ...COMMON_UNITS] }], | ||
"bg-image": ["bg-stripe-gradient"], | ||
"min-w": [ | ||
{ | ||
"min-w": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
], | ||
"min-h": [ | ||
{ | ||
"min-h": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
] | ||
} | ||
var tv = (0, import_tailwind_variants.createTV)({ | ||
twMerge: true, | ||
twMergeConfig: { | ||
theme: { | ||
opacity: ["disabled"], | ||
spacing: ["divider", "unit", ...mappedSpacingScaleKeys], | ||
borderWidth: COMMON_UNITS, | ||
borderRadius: COMMON_UNITS | ||
}, | ||
classGroups: { | ||
shadow: [{ shadow: COMMON_UNITS }], | ||
"font-size": [{ text: ["tiny", ...COMMON_UNITS] }], | ||
"bg-image": ["bg-stripe-gradient"], | ||
"min-w": [ | ||
{ | ||
"min-w": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
], | ||
"min-h": [ | ||
{ | ||
"min-h": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
] | ||
} | ||
}); | ||
}; | ||
} | ||
}); | ||
@@ -163,2 +156,26 @@ // src/utils.ts | ||
} | ||
function getClassNamesWithProps({ props, defaultVariants, customTv, hasSlots }) { | ||
var _a; | ||
const [baseProps, variantProps] = mapPropsVariants(props, customTv.variantKeys, false); | ||
const newProps = { ...defaultVariants, ...baseProps }; | ||
let classNames = {}; | ||
const result = customTv(variantProps); | ||
if (!hasSlots) { | ||
newProps.className = cn(result, props.className); | ||
} else { | ||
Object.entries(result).forEach(([key, value]) => { | ||
const slotResult = value(); | ||
if (typeof slotResult === "string") { | ||
classNames[key] = slotResult; | ||
} | ||
}); | ||
Object.entries((_a = props.classNames) != null ? _a : {}).forEach(([key, value]) => { | ||
classNames[key] = cn(classNames[key], value); | ||
}); | ||
} | ||
if (Object.keys(classNames).length !== 0) { | ||
newProps.classNames = classNames; | ||
} | ||
return newProps; | ||
} | ||
function extendVariants(BaseComponent, styles = {}, opts = {}) { | ||
@@ -181,26 +198,22 @@ var _a, _b; | ||
); | ||
const ForwardedComponent = React.forwardRef((originalProps, ref) => { | ||
var _a2; | ||
const [baseProps, variantProps] = mapPropsVariants(originalProps, customTv.variantKeys, false); | ||
const newProps = { ...defaultVariants, ...baseProps, ref }; | ||
let classNames = {}; | ||
const result = React.useMemo(() => customTv(variantProps), [...Object.values(variantProps)]); | ||
if (!hasSlots) { | ||
newProps.className = cn(result, originalProps.className); | ||
} else { | ||
Object.entries(result).forEach(([key, value]) => { | ||
const slotResult = value(); | ||
if (typeof slotResult === "string") { | ||
classNames[key] = slotResult; | ||
} | ||
const ForwardedComponent = React.forwardRef((originalProps = {}, ref) => { | ||
const newProps = getClassNamesWithProps({ | ||
props: originalProps, | ||
defaultVariants, | ||
customTv, | ||
hasSlots | ||
}); | ||
return React.createElement(BaseComponent, { ...originalProps, ...newProps, ref }); | ||
}); | ||
if (BaseComponent.getCollectionNode) { | ||
ForwardedComponent.getCollectionNode = (itemProps) => { | ||
const newProps = getClassNamesWithProps({ | ||
props: itemProps, | ||
defaultVariants, | ||
customTv, | ||
hasSlots | ||
}); | ||
Object.entries((_a2 = originalProps.classNames) != null ? _a2 : {}).forEach(([key, value]) => { | ||
classNames[key] = cn(classNames[key], value); | ||
}); | ||
} | ||
if (Object.keys(classNames).length !== 0) { | ||
newProps.classNames = classNames; | ||
} | ||
return React.createElement(BaseComponent, newProps); | ||
}); | ||
return BaseComponent.getCollectionNode({ ...itemProps, ...newProps }); | ||
}; | ||
} | ||
ForwardedComponent.displayName = `Extended(${BaseComponent.displayName || BaseComponent.name})`; | ||
@@ -207,0 +220,0 @@ return ForwardedComponent; |
@@ -153,35 +153,28 @@ "use strict"; | ||
var COMMON_UNITS = ["small", "medium", "large"]; | ||
var tv = (options, config) => { | ||
var _a, _b, _c; | ||
return (0, import_tailwind_variants.tv)(options, { | ||
...config, | ||
twMerge: (_a = config == null ? void 0 : config.twMerge) != null ? _a : true, | ||
twMergeConfig: { | ||
...config == null ? void 0 : config.twMergeConfig, | ||
theme: { | ||
...(_b = config == null ? void 0 : config.twMergeConfig) == null ? void 0 : _b.theme, | ||
opacity: ["disabled"], | ||
spacing: ["divider", "unit", ...mappedSpacingScaleKeys], | ||
borderWidth: COMMON_UNITS, | ||
borderRadius: COMMON_UNITS | ||
}, | ||
classGroups: { | ||
...(_c = config == null ? void 0 : config.twMergeConfig) == null ? void 0 : _c.classGroups, | ||
shadow: [{ shadow: COMMON_UNITS }], | ||
"font-size": [{ text: ["tiny", ...COMMON_UNITS] }], | ||
"bg-image": ["bg-stripe-gradient"], | ||
"min-w": [ | ||
{ | ||
"min-w": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
], | ||
"min-h": [ | ||
{ | ||
"min-h": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
] | ||
} | ||
var tv = (0, import_tailwind_variants.createTV)({ | ||
twMerge: true, | ||
twMergeConfig: { | ||
theme: { | ||
opacity: ["disabled"], | ||
spacing: ["divider", "unit", ...mappedSpacingScaleKeys], | ||
borderWidth: COMMON_UNITS, | ||
borderRadius: COMMON_UNITS | ||
}, | ||
classGroups: { | ||
shadow: [{ shadow: COMMON_UNITS }], | ||
"font-size": [{ text: ["tiny", ...COMMON_UNITS] }], | ||
"bg-image": ["bg-stripe-gradient"], | ||
"min-w": [ | ||
{ | ||
"min-w": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
], | ||
"min-h": [ | ||
{ | ||
"min-h": ["unit", ...mappedSpacingScaleKeys] | ||
} | ||
] | ||
} | ||
}); | ||
}; | ||
} | ||
}); | ||
@@ -201,2 +194,26 @@ // src/extend-variants.js | ||
} | ||
function getClassNamesWithProps({ props, defaultVariants, customTv, hasSlots }) { | ||
var _a; | ||
const [baseProps, variantProps] = mapPropsVariants(props, customTv.variantKeys, false); | ||
const newProps = { ...defaultVariants, ...baseProps }; | ||
let classNames = {}; | ||
const result = customTv(variantProps); | ||
if (!hasSlots) { | ||
newProps.className = cn(result, props.className); | ||
} else { | ||
Object.entries(result).forEach(([key, value]) => { | ||
const slotResult = value(); | ||
if (typeof slotResult === "string") { | ||
classNames[key] = slotResult; | ||
} | ||
}); | ||
Object.entries((_a = props.classNames) != null ? _a : {}).forEach(([key, value]) => { | ||
classNames[key] = cn(classNames[key], value); | ||
}); | ||
} | ||
if (Object.keys(classNames).length !== 0) { | ||
newProps.classNames = classNames; | ||
} | ||
return newProps; | ||
} | ||
function extendVariants(BaseComponent, styles = {}, opts = {}) { | ||
@@ -219,26 +236,22 @@ var _a, _b; | ||
); | ||
const ForwardedComponent = React.forwardRef((originalProps, ref) => { | ||
var _a2; | ||
const [baseProps, variantProps] = mapPropsVariants(originalProps, customTv.variantKeys, false); | ||
const newProps = { ...defaultVariants, ...baseProps, ref }; | ||
let classNames = {}; | ||
const result = React.useMemo(() => customTv(variantProps), [...Object.values(variantProps)]); | ||
if (!hasSlots) { | ||
newProps.className = cn(result, originalProps.className); | ||
} else { | ||
Object.entries(result).forEach(([key, value]) => { | ||
const slotResult = value(); | ||
if (typeof slotResult === "string") { | ||
classNames[key] = slotResult; | ||
} | ||
const ForwardedComponent = React.forwardRef((originalProps = {}, ref) => { | ||
const newProps = getClassNamesWithProps({ | ||
props: originalProps, | ||
defaultVariants, | ||
customTv, | ||
hasSlots | ||
}); | ||
return React.createElement(BaseComponent, { ...originalProps, ...newProps, ref }); | ||
}); | ||
if (BaseComponent.getCollectionNode) { | ||
ForwardedComponent.getCollectionNode = (itemProps) => { | ||
const newProps = getClassNamesWithProps({ | ||
props: itemProps, | ||
defaultVariants, | ||
customTv, | ||
hasSlots | ||
}); | ||
Object.entries((_a2 = originalProps.classNames) != null ? _a2 : {}).forEach(([key, value]) => { | ||
classNames[key] = cn(classNames[key], value); | ||
}); | ||
} | ||
if (Object.keys(classNames).length !== 0) { | ||
newProps.classNames = classNames; | ||
} | ||
return React.createElement(BaseComponent, newProps); | ||
}); | ||
return BaseComponent.getCollectionNode({ ...itemProps, ...newProps }); | ||
}; | ||
} | ||
ForwardedComponent.displayName = `Extended(${BaseComponent.displayName || BaseComponent.name})`; | ||
@@ -245,0 +258,0 @@ return ForwardedComponent; |
@@ -37,3 +37,3 @@ /** | ||
type Merge<M, N> = N extends Record<string, unknown> ? M : Omit<M, keyof N> & N; | ||
type HTMLNextUIProps<T extends As = "div", OmitKeys extends keyof any = never> = Omit<PropsOf<T>, "ref" | "color" | "slot" | OmitKeys> & { | ||
type HTMLNextUIProps<T extends As = "div", OmitKeys extends keyof any = never> = Omit<PropsOf<T>, "ref" | "color" | "slot" | "defaultChecked" | "defaultValue" | OmitKeys> & { | ||
as?: As; | ||
@@ -40,0 +40,0 @@ }; |
{ | ||
"name": "@nextui-org/system-rsc", | ||
"version": "0.0.0-dev-v2-20230916212336", | ||
"version": "0.0.0-dev-v2-20231103142249", | ||
"description": "NextUI system primitives compatibles with RSC imports", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"tailwind-variants": "^0.1.14", | ||
"tailwind-variants": "^0.1.18", | ||
"clsx": "^1.2.1" | ||
@@ -34,0 +34,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37672
1108
Updatedtailwind-variants@^0.1.18