mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
feat(system): tokens types mapped to use the prop without the "$" symbol
This commit is contained in:
parent
47d765d295
commit
9ad17e510a
@ -34,7 +34,8 @@
|
|||||||
"routes": [
|
"routes": [
|
||||||
{
|
{
|
||||||
"title": "Default theme",
|
"title": "Default theme",
|
||||||
"path": "/docs/theme/default-theme.mdx"
|
"path": "/docs/theme/default-theme.mdx",
|
||||||
|
"updated": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Customize theme",
|
"title": "Customize theme",
|
||||||
|
|||||||
@ -450,9 +450,9 @@ export default {
|
|||||||
|
|
||||||
<Spacer y={2} />
|
<Spacer y={2} />
|
||||||
|
|
||||||
### Border weights
|
### Border widths
|
||||||
|
|
||||||
NextUI includes by default a set of common border weights.
|
NextUI includes by default a set of common border widths.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
export default {
|
export default {
|
||||||
@ -463,7 +463,7 @@ export default {
|
|||||||
fontWeights: {...}, // font weights object
|
fontWeights: {...}, // font weights object
|
||||||
lineHeights: {...}, // line heights object
|
lineHeights: {...}, // line heights object
|
||||||
radii: {...}, // border radius object
|
radii: {...}, // border radius object
|
||||||
borderWeights: {
|
borderWidths: {
|
||||||
light: '1px',
|
light: '1px',
|
||||||
normal: '2px',
|
normal: '2px',
|
||||||
bold: '3px',
|
bold: '3px',
|
||||||
|
|||||||
@ -1,11 +1,20 @@
|
|||||||
import {BaseItem, ItemProps} from "@nextui-org/aria-utils";
|
import {BaseItem, ItemProps} from "@nextui-org/aria-utils";
|
||||||
import {CSS} from "@nextui-org/system";
|
import {CSSProp} from "@nextui-org/system";
|
||||||
import {FocusableProps} from "@react-types/shared";
|
import {FocusableProps} from "@react-types/shared";
|
||||||
import {ReactNode} from "react";
|
import {ReactNode} from "react";
|
||||||
|
|
||||||
type RenderIndicatorProps = {
|
export type RenderIndicatorProps = {
|
||||||
|
/**
|
||||||
|
* The current indicator
|
||||||
|
*/
|
||||||
indicator?: ReactNode;
|
indicator?: ReactNode;
|
||||||
|
/**
|
||||||
|
* The current open status.
|
||||||
|
*/
|
||||||
isOpen?: boolean;
|
isOpen?: boolean;
|
||||||
|
/**
|
||||||
|
* The current disabled status.
|
||||||
|
*/
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -18,8 +27,10 @@ export interface CollapseItemBaseProps<T extends object = {}>
|
|||||||
children?: ReactNode | null;
|
children?: ReactNode | null;
|
||||||
/**
|
/**
|
||||||
* The collapse item `expanded` indicator, it's usually an arrow icon.
|
* The collapse item `expanded` indicator, it's usually an arrow icon.
|
||||||
|
* If you pass a function, NextUI will expose the current indicator and the open status,
|
||||||
|
* In case you want to use a custom indicator or muodify the current one.
|
||||||
*/
|
*/
|
||||||
indicator?: ReactNode | null;
|
indicator?: ReactNode | ((props: RenderIndicatorProps) => ReactNode) | null;
|
||||||
/**
|
/**
|
||||||
* The collapse item subtitle.
|
* The collapse item subtitle.
|
||||||
*/
|
*/
|
||||||
@ -34,12 +45,12 @@ export interface CollapseItemBaseProps<T extends object = {}>
|
|||||||
* The border weight for bordered collapse item variation.
|
* The border weight for bordered collapse item variation.
|
||||||
* @default "normal"
|
* @default "normal"
|
||||||
*/
|
*/
|
||||||
borderWeight?: CSS["borderWidth"];
|
borderWeight?: CSSProp["borderWidth"];
|
||||||
/**
|
/**
|
||||||
* The border weight for the collapse item divider.
|
* The border weight for the collapse item divider.
|
||||||
* @default "light"
|
* @default "light"
|
||||||
*/
|
*/
|
||||||
dividerWeight?: CSS["borderWidth"];
|
dividerWeight?: CSSProp["borderWidth"];
|
||||||
/**
|
/**
|
||||||
* Whether the collapse item have a bottom border.
|
* Whether the collapse item have a bottom border.
|
||||||
* @default true
|
* @default true
|
||||||
@ -50,16 +61,6 @@ export interface CollapseItemBaseProps<T extends object = {}>
|
|||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
disableAnimation?: boolean;
|
disableAnimation?: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* If you pass this function NextUI will expose the current indicator and the open status, In case you want to use a custom indicator or muodify the current one.
|
|
||||||
* @param indicator The current indicator
|
|
||||||
* @param isOpen The current open status.
|
|
||||||
* @param isDisabled The current disabled status.
|
|
||||||
*
|
|
||||||
* @returns The indicator to be used.
|
|
||||||
*/
|
|
||||||
renderIndicator?: (props: RenderIndicatorProps) => ReactNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const CollapseItem = BaseItem as (props: CollapseItemBaseProps) => JSX.Element;
|
const CollapseItem = BaseItem as (props: CollapseItemBaseProps) => JSX.Element;
|
||||||
|
|||||||
@ -49,12 +49,12 @@ const CollapseItem = forwardRef<CollapseItemProps, "div">((props, ref) => {
|
|||||||
}, [indicator]);
|
}, [indicator]);
|
||||||
|
|
||||||
const indicatorComponent = useMemo(() => {
|
const indicatorComponent = useMemo(() => {
|
||||||
if (typeof item.props?.renderIndicator === "function") {
|
if (typeof item.props?.indicator === "function") {
|
||||||
return item.props?.renderIndicator({indicator, isOpen, isDisabled});
|
return item.props?.indicator({indicator, isOpen, isDisabled});
|
||||||
}
|
}
|
||||||
|
|
||||||
return indicatorWrapper;
|
return indicatorWrapper;
|
||||||
}, [item.props?.renderIndicator, indicator, indicatorWrapper, isOpen, isDisabled]);
|
}, [item.props?.indicator, indicator, indicatorWrapper, isOpen, isDisabled]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledCollapseItem
|
<StyledCollapseItem
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
// export types
|
// export types
|
||||||
export type {CollapseProps} from "./collapse";
|
export type {CollapseProps} from "./collapse";
|
||||||
|
export type {CollapseItemProps} from "./collapse-item";
|
||||||
|
export type {RenderIndicatorProps} from "./base/collapse-item-base";
|
||||||
|
|
||||||
// export component
|
// export component
|
||||||
export {default as Collapse} from "./collapse";
|
export {default as Collapse} from "./collapse";
|
||||||
|
|||||||
@ -36,12 +36,6 @@ export interface UseCollapseItemProps<T extends object> extends CollapseItemBase
|
|||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// subtitle?: ReactNode | string; //TODO: unique per item
|
|
||||||
// borderWeight?: CSS["borderWidth"];
|
|
||||||
// dividerWeight?: CSS["borderWidth"];
|
|
||||||
// withDivider?: boolean;
|
|
||||||
// disableAnimation?: boolean;
|
|
||||||
|
|
||||||
export function useCollapseItem<T extends object>(props: UseCollapseItemProps<T>) {
|
export function useCollapseItem<T extends object>(props: UseCollapseItemProps<T>) {
|
||||||
const {item, ...propsWithoutItem} = props;
|
const {item, ...propsWithoutItem} = props;
|
||||||
|
|
||||||
@ -51,10 +45,13 @@ export function useCollapseItem<T extends object>(props: UseCollapseItemProps<T>
|
|||||||
as = item.props?.as,
|
as = item.props?.as,
|
||||||
state,
|
state,
|
||||||
focusedKey,
|
focusedKey,
|
||||||
|
subtitle = item.props?.subtitle,
|
||||||
indicator = item.props?.indicator ?? <CollapseIcon />,
|
indicator = item.props?.indicator ?? <CollapseIcon />,
|
||||||
variant = item.props?.variant ?? "default",
|
variant = item.props?.variant ?? "default",
|
||||||
|
withDivider = item.props?.withDivider ?? true,
|
||||||
borderWeight = item.props?.borderWeight ?? "normal",
|
borderWeight = item.props?.borderWeight ?? "normal",
|
||||||
dividerWeight = item.props?.dividerWeight ?? "light",
|
dividerWeight = item.props?.dividerWeight ?? "light",
|
||||||
|
disableAnimation = item.props?.disableAnimation ?? false,
|
||||||
isDisabled: groupDisabled = false,
|
isDisabled: groupDisabled = false,
|
||||||
onFocusChange,
|
onFocusChange,
|
||||||
...otherProps
|
...otherProps
|
||||||
@ -98,10 +95,13 @@ export function useCollapseItem<T extends object>(props: UseCollapseItemProps<T>
|
|||||||
item,
|
item,
|
||||||
css: itemCss,
|
css: itemCss,
|
||||||
indicator,
|
indicator,
|
||||||
|
subtitle,
|
||||||
variant,
|
variant,
|
||||||
isDisabled,
|
isDisabled,
|
||||||
isOpen,
|
isOpen,
|
||||||
isFocusVisible,
|
isFocusVisible,
|
||||||
|
withDivider,
|
||||||
|
disableAnimation,
|
||||||
buttonProps,
|
buttonProps,
|
||||||
regionProps,
|
regionProps,
|
||||||
focusProps,
|
focusProps,
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export default {
|
|||||||
|
|
||||||
export const Default = () => (
|
export const Default = () => (
|
||||||
<Collapse selectionMode="single">
|
<Collapse selectionMode="single">
|
||||||
<Collapse.Item key="1" title="Your files">
|
<Collapse.Item key="1" dividerWeight="" title="Your files">
|
||||||
file
|
file
|
||||||
</Collapse.Item>
|
</Collapse.Item>
|
||||||
<Collapse.Item key="2" title="Shared with you">
|
<Collapse.Item key="2" title="Shared with you">
|
||||||
@ -32,7 +32,7 @@ export const CustomIndicator = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Collapse selectionMode="single">
|
<Collapse selectionMode="single">
|
||||||
<Collapse.Item key="1" renderIndicator={renderIndicator} title="Your files">
|
<Collapse.Item key="1" indicator={renderIndicator} title="Your files">
|
||||||
file
|
file
|
||||||
</Collapse.Item>
|
</Collapse.Item>
|
||||||
<Collapse.Item key="2" title="Shared with you">
|
<Collapse.Item key="2" title="Shared with you">
|
||||||
|
|||||||
@ -133,7 +133,7 @@ export const defaultTokens = {
|
|||||||
10: "1000",
|
10: "1000",
|
||||||
max: "9999",
|
max: "9999",
|
||||||
},
|
},
|
||||||
borderWeights: {
|
borderWidths: {
|
||||||
light: "1px",
|
light: "1px",
|
||||||
normal: "2px",
|
normal: "2px",
|
||||||
bold: "3px",
|
bold: "3px",
|
||||||
@ -515,7 +515,6 @@ export const defaultThemeMap = {
|
|||||||
inlineSize: "space",
|
inlineSize: "space",
|
||||||
minInlineSize: "space",
|
minInlineSize: "space",
|
||||||
maxInlineSize: "space",
|
maxInlineSize: "space",
|
||||||
borderWidth: "borderWeights",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export declare namespace ConfigType {
|
|||||||
space?: {[token in number | string]: boolean | number | string};
|
space?: {[token in number | string]: boolean | number | string};
|
||||||
radii?: {[token in number | string]: boolean | number | string};
|
radii?: {[token in number | string]: boolean | number | string};
|
||||||
zIndices?: {[token in number | string]: boolean | number | string};
|
zIndices?: {[token in number | string]: boolean | number | string};
|
||||||
borderWeights?: {[token in number | string]: boolean | number | string};
|
borderWidths?: {[token in number | string]: boolean | number | string};
|
||||||
colors?: {[token in number | string]: boolean | number | string};
|
colors?: {[token in number | string]: boolean | number | string};
|
||||||
shadows?: {[token in number | string]: boolean | number | string};
|
shadows?: {[token in number | string]: boolean | number | string};
|
||||||
dropShadows?: {[token in number | string]: boolean | number | string};
|
dropShadows?: {[token in number | string]: boolean | number | string};
|
||||||
@ -60,6 +60,7 @@ export type StitchesTheme = typeof theme;
|
|||||||
export type CSSComponent = typeof css;
|
export type CSSComponent = typeof css;
|
||||||
|
|
||||||
// theme types
|
// theme types
|
||||||
|
export type BaseThemeMap = StitchesConfig["themeMap"];
|
||||||
export type BaseTheme = ConfigType.Theme;
|
export type BaseTheme = ConfigType.Theme;
|
||||||
export type NextUITheme = StitchesTheme;
|
export type NextUITheme = StitchesTheme;
|
||||||
export type ThemeType = "dark" | "light";
|
export type ThemeType = "dark" | "light";
|
||||||
@ -76,11 +77,34 @@ export interface TokenValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Theme = {
|
export type Theme = {
|
||||||
|
/**
|
||||||
|
* The theme type.
|
||||||
|
* @default "light"
|
||||||
|
*/
|
||||||
type?: ThemeType | string;
|
type?: ThemeType | string;
|
||||||
|
/**
|
||||||
|
* The stitches theme class name.
|
||||||
|
* @see https://stitches.dev/docs/theming#add-a-new-theme
|
||||||
|
*/
|
||||||
className?: string;
|
className?: string;
|
||||||
|
/**
|
||||||
|
* The stitches theme tokens object.
|
||||||
|
*/
|
||||||
theme?: BaseTheme;
|
theme?: BaseTheme;
|
||||||
|
/**
|
||||||
|
* The stitches theme media object.
|
||||||
|
* @see https://stitches.dev/docs/breakpoints
|
||||||
|
*/
|
||||||
media?: ConfigType.Media;
|
media?: ConfigType.Media;
|
||||||
|
/**
|
||||||
|
* The theme utils object.
|
||||||
|
* @see https://stitches.dev/docs/utils
|
||||||
|
*/
|
||||||
utils?: ConfigType.Utils;
|
utils?: ConfigType.Utils;
|
||||||
|
/**
|
||||||
|
* The stitches theme themeMap object.
|
||||||
|
* @see https://stitches.dev/docs/tokens#property-mapping
|
||||||
|
*/
|
||||||
themeMap?: ConfigType.ThemeMap;
|
themeMap?: ConfigType.ThemeMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,3 +113,23 @@ export type NextUIThemeContext = {
|
|||||||
theme?: NextUITheme;
|
theme?: NextUITheme;
|
||||||
isDark?: boolean;
|
isDark?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Globals = "inherit" | "initial" | "revert" | "unset";
|
||||||
|
|
||||||
|
type Index = (number | string) & Record<never, never>;
|
||||||
|
|
||||||
|
type TokenByScaleName<ScaleName, Theme> = ScaleName extends keyof Theme
|
||||||
|
? keyof Theme[ScaleName]
|
||||||
|
: never;
|
||||||
|
|
||||||
|
type TokenByPropertyName<PropertyName, Theme, ThemeMap> = PropertyName extends keyof ThemeMap
|
||||||
|
? TokenByScaleName<ThemeMap[PropertyName], Theme>
|
||||||
|
: never;
|
||||||
|
|
||||||
|
export type CSSProp = {
|
||||||
|
[K in keyof CSSProperties]?:
|
||||||
|
| TokenByPropertyName<K, NextUITheme, BaseThemeMap>
|
||||||
|
| Globals
|
||||||
|
| Index
|
||||||
|
| undefined;
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user