@tuuject/koi-react 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/alert/Alert.d.ts +13 -0
- package/dist/alert/Alert.js +16 -0
- package/dist/avatar/Avatar.d.ts +7 -0
- package/dist/avatar/Avatar.js +10 -0
- package/dist/badge/Badge.d.ts +7 -0
- package/dist/badge/Badge.js +8 -0
- package/dist/button/Button.d.ts +22 -0
- package/dist/button/Button.js +28 -0
- package/dist/card/Card.d.ts +9 -0
- package/dist/card/Card.js +8 -0
- package/dist/chat-bubble/ChatBubble.d.ts +7 -0
- package/dist/chat-bubble/ChatBubble.js +7 -0
- package/dist/checkbox/Checkbox.d.ts +18 -0
- package/dist/checkbox/Checkbox.js +25 -0
- package/dist/dialog/Dialog.d.ts +13 -0
- package/dist/dialog/Dialog.js +38 -0
- package/dist/divider/Divider.d.ts +6 -0
- package/dist/divider/Divider.js +17 -0
- package/dist/field/Field.d.ts +14 -0
- package/dist/field/Field.js +19 -0
- package/dist/field/context.d.ts +5 -0
- package/dist/field/context.js +2 -0
- package/dist/icons.d.ts +26 -0
- package/dist/icons.js +46 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +30 -0
- package/dist/input/Input.d.ts +9 -0
- package/dist/input/Input.js +15 -0
- package/dist/link/Link.d.ts +11 -0
- package/dist/link/Link.js +17 -0
- package/dist/pagination/Pagination.d.ts +7 -0
- package/dist/pagination/Pagination.js +26 -0
- package/dist/panda/buildinfo.json +10442 -0
- package/dist/panda/lib.json +18 -0
- package/dist/panda/preset.mjs +3907 -0
- package/dist/progress/Progress.d.ts +7 -0
- package/dist/progress/Progress.js +17 -0
- package/dist/prose/Prose.d.ts +10 -0
- package/dist/prose/Prose.js +10 -0
- package/dist/radio-group/RadioGroup.d.ts +15 -0
- package/dist/radio-group/RadioGroup.js +26 -0
- package/dist/select/Select.d.ts +11 -0
- package/dist/select/Select.js +21 -0
- package/dist/select/SelectPanel.d.ts +24 -0
- package/dist/select/SelectPanel.js +105 -0
- package/dist/shape.d.ts +16 -0
- package/dist/shape.js +17 -0
- package/dist/skeleton/Skeleton.d.ts +8 -0
- package/dist/skeleton/Skeleton.js +8 -0
- package/dist/spinner/Spinner.d.ts +7 -0
- package/dist/spinner/Spinner.js +13 -0
- package/dist/switch/Switch.d.ts +22 -0
- package/dist/switch/Switch.js +23 -0
- package/dist/table/DataTable.d.ts +12 -0
- package/dist/table/DataTable.js +12 -0
- package/dist/table/Table.d.ts +38 -0
- package/dist/table/Table.js +45 -0
- package/dist/tabs/Tabs.d.ts +11 -0
- package/dist/tabs/Tabs.js +20 -0
- package/dist/tag/Tag.d.ts +6 -0
- package/dist/tag/Tag.js +15 -0
- package/dist/textarea/Textarea.d.ts +9 -0
- package/dist/textarea/Textarea.js +14 -0
- package/dist/toast/Toast.d.ts +23 -0
- package/dist/toast/Toast.js +80 -0
- package/dist/tooltip/Tooltip.d.ts +9 -0
- package/dist/tooltip/Tooltip.js +29 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +1 -0
- package/package.json +218 -3
- package/styled-system/css/conditions.d.ts +7 -0
- package/styled-system/css/conditions.js +32 -0
- package/styled-system/css/css.d.ts +22 -0
- package/styled-system/css/css.js +63 -0
- package/styled-system/css/cva.d.ts +5 -0
- package/styled-system/css/cva.js +51 -0
- package/styled-system/css/cx.d.ts +6 -0
- package/styled-system/css/cx.js +16 -0
- package/styled-system/css/first-that-works.d.ts +22 -0
- package/styled-system/css/first-that-works.js +1 -0
- package/styled-system/css/index.d.ts +8 -0
- package/styled-system/css/index.js +8 -0
- package/styled-system/css/keyframes.d.ts +5 -0
- package/styled-system/css/keyframes.js +8 -0
- package/styled-system/css/position-try.d.ts +5 -0
- package/styled-system/css/position-try.js +11 -0
- package/styled-system/css/sva.d.ts +3 -0
- package/styled-system/css/sva.js +49 -0
- package/styled-system/css/view-transition.d.ts +7 -0
- package/styled-system/css/view-transition.js +18 -0
- package/styled-system/helpers.d.ts +67 -0
- package/styled-system/helpers.js +624 -0
- package/styled-system/jsx/aspect-ratio.d.ts +7 -0
- package/styled-system/jsx/aspect-ratio.js +11 -0
- package/styled-system/jsx/bleed.d.ts +7 -0
- package/styled-system/jsx/bleed.js +11 -0
- package/styled-system/jsx/box.d.ts +7 -0
- package/styled-system/jsx/box.js +11 -0
- package/styled-system/jsx/center.d.ts +7 -0
- package/styled-system/jsx/center.js +11 -0
- package/styled-system/jsx/circle.d.ts +7 -0
- package/styled-system/jsx/circle.js +11 -0
- package/styled-system/jsx/container.d.ts +7 -0
- package/styled-system/jsx/container.js +11 -0
- package/styled-system/jsx/cq.d.ts +7 -0
- package/styled-system/jsx/cq.js +11 -0
- package/styled-system/jsx/create-recipe-context.d.ts +32 -0
- package/styled-system/jsx/create-recipe-context.js +38 -0
- package/styled-system/jsx/create-slot-recipe-context.d.ts +48 -0
- package/styled-system/jsx/create-slot-recipe-context.js +116 -0
- package/styled-system/jsx/divider.d.ts +7 -0
- package/styled-system/jsx/divider.js +11 -0
- package/styled-system/jsx/factory.d.ts +3 -0
- package/styled-system/jsx/factory.js +91 -0
- package/styled-system/jsx/flex.d.ts +7 -0
- package/styled-system/jsx/flex.js +11 -0
- package/styled-system/jsx/float.d.ts +7 -0
- package/styled-system/jsx/float.js +11 -0
- package/styled-system/jsx/grid-item.d.ts +7 -0
- package/styled-system/jsx/grid-item.js +11 -0
- package/styled-system/jsx/grid.d.ts +7 -0
- package/styled-system/jsx/grid.js +11 -0
- package/styled-system/jsx/helper.d.ts +34 -0
- package/styled-system/jsx/helper.js +83 -0
- package/styled-system/jsx/hstack.d.ts +7 -0
- package/styled-system/jsx/hstack.js +11 -0
- package/styled-system/jsx/index.d.ts +25 -0
- package/styled-system/jsx/index.js +24 -0
- package/styled-system/jsx/is-valid-prop.d.ts +7 -0
- package/styled-system/jsx/is-valid-prop.js +12 -0
- package/styled-system/jsx/link-overlay.d.ts +7 -0
- package/styled-system/jsx/link-overlay.js +11 -0
- package/styled-system/jsx/spacer.d.ts +7 -0
- package/styled-system/jsx/spacer.js +11 -0
- package/styled-system/jsx/square.d.ts +7 -0
- package/styled-system/jsx/square.js +11 -0
- package/styled-system/jsx/stack.d.ts +7 -0
- package/styled-system/jsx/stack.js +11 -0
- package/styled-system/jsx/visually-hidden.d.ts +7 -0
- package/styled-system/jsx/visually-hidden.js +11 -0
- package/styled-system/jsx/vstack.d.ts +7 -0
- package/styled-system/jsx/vstack.js +11 -0
- package/styled-system/jsx/wrap.d.ts +7 -0
- package/styled-system/jsx/wrap.js +11 -0
- package/styled-system/patterns/aspect-ratio.d.ts +19 -0
- package/styled-system/patterns/aspect-ratio.js +37 -0
- package/styled-system/patterns/bleed.d.ts +20 -0
- package/styled-system/patterns/bleed.js +30 -0
- package/styled-system/patterns/box.d.ts +17 -0
- package/styled-system/patterns/box.js +16 -0
- package/styled-system/patterns/center.d.ts +19 -0
- package/styled-system/patterns/center.js +22 -0
- package/styled-system/patterns/circle.d.ts +19 -0
- package/styled-system/patterns/circle.js +26 -0
- package/styled-system/patterns/container.d.ts +17 -0
- package/styled-system/patterns/container.js +26 -0
- package/styled-system/patterns/cq.d.ts +21 -0
- package/styled-system/patterns/cq.js +24 -0
- package/styled-system/patterns/divider.d.ts +22 -0
- package/styled-system/patterns/divider.js +31 -0
- package/styled-system/patterns/flex.d.ts +25 -0
- package/styled-system/patterns/flex.js +27 -0
- package/styled-system/patterns/float.d.ts +23 -0
- package/styled-system/patterns/float.js +84 -0
- package/styled-system/patterns/grid-item.d.ts +24 -0
- package/styled-system/patterns/grid-item.js +26 -0
- package/styled-system/patterns/grid.d.ts +24 -0
- package/styled-system/patterns/grid.js +30 -0
- package/styled-system/patterns/hstack.d.ts +20 -0
- package/styled-system/patterns/hstack.js +27 -0
- package/styled-system/patterns/index.d.ts +20 -0
- package/styled-system/patterns/index.js +20 -0
- package/styled-system/patterns/link-overlay.d.ts +17 -0
- package/styled-system/patterns/link-overlay.js +25 -0
- package/styled-system/patterns/runtime.js +25 -0
- package/styled-system/patterns/spacer.d.ts +20 -0
- package/styled-system/patterns/spacer.js +26 -0
- package/styled-system/patterns/square.d.ts +19 -0
- package/styled-system/patterns/square.js +25 -0
- package/styled-system/patterns/stack.d.ts +22 -0
- package/styled-system/patterns/stack.js +30 -0
- package/styled-system/patterns/visually-hidden.d.ts +17 -0
- package/styled-system/patterns/visually-hidden.js +19 -0
- package/styled-system/patterns/vstack.d.ts +20 -0
- package/styled-system/patterns/vstack.js +27 -0
- package/styled-system/patterns/wrap.d.ts +23 -0
- package/styled-system/patterns/wrap.js +26 -0
- package/styled-system/recipes/alert.d.ts +19 -0
- package/styled-system/recipes/alert.js +5 -0
- package/styled-system/recipes/avatar.d.ts +19 -0
- package/styled-system/recipes/avatar.js +5 -0
- package/styled-system/recipes/badge.d.ts +18 -0
- package/styled-system/recipes/badge.js +5 -0
- package/styled-system/recipes/button.d.ts +20 -0
- package/styled-system/recipes/button.js +5 -0
- package/styled-system/recipes/card.d.ts +19 -0
- package/styled-system/recipes/card.js +5 -0
- package/styled-system/recipes/chat-bubble.d.ts +16 -0
- package/styled-system/recipes/chat-bubble.js +5 -0
- package/styled-system/recipes/checkbox.d.ts +16 -0
- package/styled-system/recipes/checkbox.js +5 -0
- package/styled-system/recipes/dialog.d.ts +18 -0
- package/styled-system/recipes/dialog.js +5 -0
- package/styled-system/recipes/field.d.ts +16 -0
- package/styled-system/recipes/field.js +5 -0
- package/styled-system/recipes/index.d.ts +27 -0
- package/styled-system/recipes/index.js +27 -0
- package/styled-system/recipes/input.d.ts +18 -0
- package/styled-system/recipes/input.js +5 -0
- package/styled-system/recipes/link.d.ts +18 -0
- package/styled-system/recipes/link.js +5 -0
- package/styled-system/recipes/pagination.d.ts +19 -0
- package/styled-system/recipes/pagination.js +5 -0
- package/styled-system/recipes/progress.d.ts +18 -0
- package/styled-system/recipes/progress.js +5 -0
- package/styled-system/recipes/prose.d.ts +16 -0
- package/styled-system/recipes/prose.js +5 -0
- package/styled-system/recipes/radio-group.d.ts +18 -0
- package/styled-system/recipes/radio-group.js +5 -0
- package/styled-system/recipes/runtime.js +133 -0
- package/styled-system/recipes/select-panel.d.ts +18 -0
- package/styled-system/recipes/select-panel.js +5 -0
- package/styled-system/recipes/select.d.ts +18 -0
- package/styled-system/recipes/select.js +5 -0
- package/styled-system/recipes/separator.d.ts +16 -0
- package/styled-system/recipes/separator.js +5 -0
- package/styled-system/recipes/skeleton.d.ts +14 -0
- package/styled-system/recipes/skeleton.js +5 -0
- package/styled-system/recipes/spinner.d.ts +16 -0
- package/styled-system/recipes/spinner.js +5 -0
- package/styled-system/recipes/switch-recipe.d.ts +16 -0
- package/styled-system/recipes/switch-recipe.js +5 -0
- package/styled-system/recipes/table.d.ts +20 -0
- package/styled-system/recipes/table.js +5 -0
- package/styled-system/recipes/tabs.d.ts +18 -0
- package/styled-system/recipes/tabs.js +5 -0
- package/styled-system/recipes/tag.d.ts +18 -0
- package/styled-system/recipes/tag.js +5 -0
- package/styled-system/recipes/textarea.d.ts +14 -0
- package/styled-system/recipes/textarea.js +5 -0
- package/styled-system/recipes/toast.d.ts +20 -0
- package/styled-system/recipes/toast.js +5 -0
- package/styled-system/recipes/tooltip.d.ts +16 -0
- package/styled-system/recipes/tooltip.js +5 -0
- package/styled-system/tokens/index.d.ts +8 -0
- package/styled-system/tokens/index.js +18 -0
- package/styled-system/types/index.d.ts +5 -0
- package/styled-system/types/jsx.d.ts +80 -0
- package/styled-system/types/pattern.d.ts +26 -0
- package/styled-system/types/recipe.d.ts +77 -0
- package/styled-system/types/system.d.ts +1645 -0
- package/styled-system/types/tokens.d.ts +47 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { center } from '../patterns/center';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Center = /* @__PURE__ */ forwardRef(function Center(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, center.propKeys)
|
|
8
|
+
const styleProps = center.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { CircleProperties } from '../patterns/circle';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface CircleProps extends CircleProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof CircleProperties> {}
|
|
7
|
+
export declare const Circle: FunctionComponent<CircleProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { circle } from '../patterns/circle';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Circle = /* @__PURE__ */ forwardRef(function Circle(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, circle.propKeys)
|
|
8
|
+
const styleProps = circle.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { ContainerProperties } from '../patterns/container';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface ContainerProps extends ContainerProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof ContainerProperties> {}
|
|
7
|
+
export declare const Container: FunctionComponent<ContainerProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { container } from '../patterns/container';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Container = /* @__PURE__ */ forwardRef(function Container(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, container.propKeys)
|
|
8
|
+
const styleProps = container.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { CqProperties } from '../patterns/cq';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface CqProps extends CqProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof CqProperties> {}
|
|
7
|
+
export declare const Cq: FunctionComponent<CqProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { cq } from '../patterns/cq';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Cq = /* @__PURE__ */ forwardRef(function Cq(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, cq.propKeys)
|
|
8
|
+
const styleProps = cq.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RecipeDefinition, RecipeRuntimeFn, RecipeSelection, RecipeVariantRecord } from '../types/recipe';
|
|
2
|
+
import type { Assign, JsxHTMLProps, JsxStyleProps } from '../types/system';
|
|
3
|
+
import type { AsProps, ComponentProps, DataAttrs, JsxFactoryOptions, UnstyledProps, WithForwardedProps } from '../types/jsx';
|
|
4
|
+
import type { ElementType, JSX, Provider } from 'react';
|
|
5
|
+
|
|
6
|
+
type AnyRecipeDefinition = RecipeDefinition<RecipeVariantRecord>;
|
|
7
|
+
interface RuntimeRecipeFn {
|
|
8
|
+
__type: unknown;
|
|
9
|
+
(props?: never): string;
|
|
10
|
+
}
|
|
11
|
+
type RecipeContextRecipe = RecipeRuntimeFn<any, any> | RuntimeRecipeFn | AnyRecipeDefinition;
|
|
12
|
+
type RecipePropsOf<R extends RecipeContextRecipe> = R extends RuntimeRecipeFn ? R['__type'] : R extends RecipeRuntimeFn<infer P, any> ? P : R extends RecipeDefinition<infer T> ? RecipeSelection<T> : never;
|
|
13
|
+
type RecipeContextComponentProps<
|
|
14
|
+
T extends ElementType,
|
|
15
|
+
R extends RecipeContextRecipe,
|
|
16
|
+
F extends string
|
|
17
|
+
> = JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, WithForwardedProps<Assign<RecipePropsOf<R>, JsxStyleProps>, T, F>>;
|
|
18
|
+
type RecipeContextComponent<
|
|
19
|
+
T extends ElementType,
|
|
20
|
+
R extends RecipeContextRecipe,
|
|
21
|
+
F extends string = never
|
|
22
|
+
> = (props: RecipeContextComponentProps<T, R, F>) => JSX.Element;
|
|
23
|
+
export interface RecipeContext<R extends RecipeContextRecipe> {
|
|
24
|
+
withContext: <
|
|
25
|
+
T extends ElementType,
|
|
26
|
+
F extends string = never
|
|
27
|
+
>(Component: T, options?: JsxFactoryOptions<ComponentProps<T>, F> | undefined) => RecipeContextComponent<T, R, F>;
|
|
28
|
+
PropsProvider: Provider<Partial<RecipePropsOf<R>> & DataAttrs>;
|
|
29
|
+
usePropsContext: () => RecipePropsOf<R> | undefined;
|
|
30
|
+
}
|
|
31
|
+
export declare function createRecipeContext<R extends RecipeContextRecipe>(recipeInput: R): RecipeContext<R>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, createElement, forwardRef } from 'react';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
import { getDisplayName } from './helper';
|
|
6
|
+
|
|
7
|
+
function resolveRecipe(recipe) {
|
|
8
|
+
if (recipe == null) throw new Error('createRecipeContext requires a recipe')
|
|
9
|
+
if (recipe.__recipe__ === true || recipe.__cva__ === true) return recipe
|
|
10
|
+
if (recipe.base || recipe.variants || recipe.defaultVariants || recipe.compoundVariants) return recipe
|
|
11
|
+
throw new Error('createRecipeContext requires a recipe')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createRecipeContext(recipeInput) {
|
|
15
|
+
const recipe = resolveRecipe(recipeInput)
|
|
16
|
+
const PropsContext = createContext(undefined)
|
|
17
|
+
const usePropsContext = () => useContext(PropsContext)
|
|
18
|
+
|
|
19
|
+
const withContext = (Component, options) => {
|
|
20
|
+
const StyledComponent = styled(Component, recipe, options)
|
|
21
|
+
const componentName = getDisplayName(Component)
|
|
22
|
+
|
|
23
|
+
const WithContext = forwardRef(function WithContext(inProps, ref) {
|
|
24
|
+
const propsContext = usePropsContext()
|
|
25
|
+
const props = propsContext ? Object.assign({}, propsContext, inProps) : inProps
|
|
26
|
+
return createElement(StyledComponent, { ...props, ref })
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
WithContext.displayName = `withContext(${componentName})`
|
|
30
|
+
return WithContext
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
withContext,
|
|
35
|
+
PropsProvider: PropsContext.Provider,
|
|
36
|
+
usePropsContext,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { RecipeSelection, SlotRecipeDefinition, SlotRecipeRuntimeFn, SlotRecipeVariantRecord } from '../types/recipe';
|
|
2
|
+
import type { Assign, JsxHTMLProps, JsxStyleProps } from '../types/system';
|
|
3
|
+
import type { AsProps, ComponentProps, DataAttrs, JsxFactoryOptions, UnstyledProps, WithForwardedProps } from '../types/jsx';
|
|
4
|
+
import type { ElementType, JSX } from 'react';
|
|
5
|
+
|
|
6
|
+
type AnySlotRecipeDefinition = SlotRecipeDefinition<string, SlotRecipeVariantRecord<string>>;
|
|
7
|
+
interface RuntimeSlotRecipeFn {
|
|
8
|
+
__type: unknown;
|
|
9
|
+
__slot: string;
|
|
10
|
+
(props?: never): unknown;
|
|
11
|
+
}
|
|
12
|
+
type SlotRecipeContextInput = SlotRecipeRuntimeFn<string, any, any> | RuntimeSlotRecipeFn | AnySlotRecipeDefinition;
|
|
13
|
+
type SlotNameOf<R extends SlotRecipeContextInput> = R extends RuntimeSlotRecipeFn ? R['__slot'] : R extends SlotRecipeRuntimeFn<infer S, any, any> ? S : R extends SlotRecipeDefinition<infer S, any> ? S : string;
|
|
14
|
+
type SlotRecipePropsOf<R extends SlotRecipeContextInput> = R extends RuntimeSlotRecipeFn ? R['__type'] : R extends SlotRecipeRuntimeFn<any, infer P, any> ? P : R extends SlotRecipeDefinition<any, infer T> ? RecipeSelection<T> : never;
|
|
15
|
+
interface WithProviderOptions<P = {}> {
|
|
16
|
+
defaultProps?: (Partial<P> & DataAttrs) | undefined;
|
|
17
|
+
}
|
|
18
|
+
type SlotRecipeProviderProps<
|
|
19
|
+
T extends ElementType,
|
|
20
|
+
R extends SlotRecipeContextInput,
|
|
21
|
+
F extends string
|
|
22
|
+
> = JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, WithForwardedProps<Assign<SlotRecipePropsOf<R>, JsxStyleProps>, T, F>>;
|
|
23
|
+
type SlotRecipeProviderComponent<
|
|
24
|
+
T extends ElementType,
|
|
25
|
+
R extends SlotRecipeContextInput,
|
|
26
|
+
F extends string = never
|
|
27
|
+
> = (props: SlotRecipeProviderProps<T, R, F>) => JSX.Element;
|
|
28
|
+
type SlotRecipeRootProviderComponent<
|
|
29
|
+
T extends ElementType,
|
|
30
|
+
R extends SlotRecipeContextInput
|
|
31
|
+
> = (props: ComponentProps<T> & UnstyledProps & SlotRecipePropsOf<R>) => JSX.Element;
|
|
32
|
+
type SlotRecipeConsumerComponent<
|
|
33
|
+
T extends ElementType,
|
|
34
|
+
F extends string = never
|
|
35
|
+
> = (props: JsxHTMLProps<ComponentProps<T> & UnstyledProps & AsProps, WithForwardedProps<JsxStyleProps, T, F>>) => JSX.Element;
|
|
36
|
+
export interface SlotRecipeContext<R extends SlotRecipeContextInput> {
|
|
37
|
+
withRootProvider: <T extends ElementType>(Component: T, options?: WithProviderOptions<ComponentProps<T>> | undefined) => SlotRecipeRootProviderComponent<T, R>;
|
|
38
|
+
withProvider: <
|
|
39
|
+
T extends ElementType,
|
|
40
|
+
F extends string = never
|
|
41
|
+
>(Component: T, slot: SlotNameOf<R>, options?: JsxFactoryOptions<ComponentProps<T>, F> | undefined) => SlotRecipeProviderComponent<T, R, F>;
|
|
42
|
+
withContext: <
|
|
43
|
+
T extends ElementType,
|
|
44
|
+
F extends string = never
|
|
45
|
+
>(Component: T, slot: SlotNameOf<R>, options?: JsxFactoryOptions<ComponentProps<T>, F> | undefined) => SlotRecipeConsumerComponent<T, F>;
|
|
46
|
+
}
|
|
47
|
+
export declare function createSlotRecipeContext<R extends SlotRecipeContextInput>(recipeInput: R): SlotRecipeContext<R>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, createElement, forwardRef } from 'react';
|
|
4
|
+
import { cx, css, sva } from '../css/index';
|
|
5
|
+
import { styled } from './factory';
|
|
6
|
+
import { getDisplayName } from './helper';
|
|
7
|
+
|
|
8
|
+
function createSafeContext(contextName) {
|
|
9
|
+
const Context = createContext(undefined)
|
|
10
|
+
const useStyleContext = (componentName, slot) => {
|
|
11
|
+
const context = useContext(Context)
|
|
12
|
+
if (context === undefined) {
|
|
13
|
+
const componentInfo = componentName ? `Component "${componentName}"` : 'A component'
|
|
14
|
+
const slotInfo = slot ? ` (slot: "${slot}")` : ''
|
|
15
|
+
throw new Error(`${componentInfo}${slotInfo} cannot access ${contextName} because it's missing its Provider.`)
|
|
16
|
+
}
|
|
17
|
+
return context
|
|
18
|
+
}
|
|
19
|
+
return [Context, useStyleContext]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolveSlotRecipe(recipe) {
|
|
23
|
+
if (recipe == null) throw new Error('createSlotRecipeContext requires a slot recipe')
|
|
24
|
+
if (typeof recipe.splitVariantProps === 'function') return recipe
|
|
25
|
+
if (recipe.slots) return recipe
|
|
26
|
+
throw new Error('createSlotRecipeContext requires a slot recipe')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createSlotRecipeContext(recipeInput) {
|
|
30
|
+
const recipe = resolveSlotRecipe(recipeInput)
|
|
31
|
+
const isRuntimeRecipe = typeof recipe.splitVariantProps === 'function'
|
|
32
|
+
const isConfigRecipe = isRuntimeRecipe && recipe.__recipe__ !== undefined
|
|
33
|
+
const recipeName = isRuntimeRecipe && recipe.__name__ ? recipe.__name__ : undefined
|
|
34
|
+
const contextName = recipeName ? `createSlotRecipeContext("${recipeName}")` : 'createSlotRecipeContext'
|
|
35
|
+
const [SlotStylesContext, useSlotStylesContext] = createSafeContext(contextName)
|
|
36
|
+
const slotRecipeFn = isRuntimeRecipe ? recipe : sva(recipe.config ?? recipe)
|
|
37
|
+
|
|
38
|
+
const resolveProps = (props, slotStyles) => {
|
|
39
|
+
const { unstyled, ...restProps } = props
|
|
40
|
+
if (unstyled) return restProps
|
|
41
|
+
if (isConfigRecipe) return { ...restProps, className: cx(slotStyles, restProps.className) }
|
|
42
|
+
return { ...restProps, className: cx(css(slotStyles), restProps.className) }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const resolveSlots = (variantProps) => {
|
|
46
|
+
const styles = isConfigRecipe ? slotRecipeFn(variantProps) : slotRecipeFn.raw(variantProps)
|
|
47
|
+
if (!isConfigRecipe) styles._classNameMap = slotRecipeFn.classNameMap
|
|
48
|
+
return styles
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const withRootProvider = (Component, options) => {
|
|
52
|
+
const WithRootProvider = (props) => {
|
|
53
|
+
const [variantProps, otherProps] = slotRecipeFn.splitVariantProps(props)
|
|
54
|
+
const resolvedSlots = resolveSlots(variantProps)
|
|
55
|
+
const mergedProps = options?.defaultProps ? Object.assign({}, options.defaultProps, otherProps) : otherProps
|
|
56
|
+
return createElement(SlotStylesContext.Provider, {
|
|
57
|
+
value: resolvedSlots,
|
|
58
|
+
children: createElement(Component, mergedProps),
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
const componentName = getDisplayName(Component)
|
|
62
|
+
WithRootProvider.displayName = `withRootProvider(${componentName})`
|
|
63
|
+
return WithRootProvider
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const withProvider = (Component, slot, options) => {
|
|
67
|
+
const StyledComponent = styled(Component, {}, options)
|
|
68
|
+
const WithProvider = forwardRef(function WithProvider(props, ref) {
|
|
69
|
+
const [variantProps, restProps] = slotRecipeFn.splitVariantProps(props)
|
|
70
|
+
const resolvedSlots = resolveSlots(variantProps)
|
|
71
|
+
if (restProps.className == null && options?.defaultProps?.className) restProps.className = options.defaultProps.className
|
|
72
|
+
const resolvedProps = resolveProps(restProps, resolvedSlots[slot])
|
|
73
|
+
options?.forwardProps?.forEach((key) => {
|
|
74
|
+
if (key in variantProps) resolvedProps[key] = variantProps[key]
|
|
75
|
+
})
|
|
76
|
+
return createElement(SlotStylesContext.Provider, {
|
|
77
|
+
value: resolvedSlots,
|
|
78
|
+
children: createElement(StyledComponent, {
|
|
79
|
+
...resolvedProps,
|
|
80
|
+
className: cx(resolvedProps.className, resolvedSlots._classNameMap?.[slot]),
|
|
81
|
+
'data-slot': slot,
|
|
82
|
+
ref,
|
|
83
|
+
}),
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
const componentName = getDisplayName(Component)
|
|
87
|
+
WithProvider.displayName = `withProvider(${componentName})`
|
|
88
|
+
return WithProvider
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const withContext = (Component, slot, options) => {
|
|
92
|
+
const StyledComponent = styled(Component, {}, options)
|
|
93
|
+
const componentName = getDisplayName(Component)
|
|
94
|
+
const WithContext = forwardRef(function WithContext(props, ref) {
|
|
95
|
+
const resolvedSlots = useSlotStylesContext(componentName, slot)
|
|
96
|
+
const nextProps = props.className == null && options?.defaultProps?.className
|
|
97
|
+
? { ...props, className: options.defaultProps.className }
|
|
98
|
+
: props
|
|
99
|
+
const resolvedProps = resolveProps(nextProps, resolvedSlots[slot])
|
|
100
|
+
return createElement(StyledComponent, {
|
|
101
|
+
...resolvedProps,
|
|
102
|
+
className: cx(resolvedProps.className, resolvedSlots._classNameMap?.[slot]),
|
|
103
|
+
'data-slot': slot,
|
|
104
|
+
ref,
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
WithContext.displayName = `withContext(${componentName})`
|
|
108
|
+
return WithContext
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
withRootProvider,
|
|
113
|
+
withProvider,
|
|
114
|
+
withContext,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { DividerProperties } from '../patterns/divider';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface DividerProps extends DividerProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof DividerProperties> {}
|
|
7
|
+
export declare const Divider: FunctionComponent<DividerProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { divider } from '../patterns/divider';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Divider = /* @__PURE__ */ forwardRef(function Divider(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, divider.propKeys)
|
|
8
|
+
const styleProps = divider.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { cx, cva } from '../css/index';
|
|
3
|
+
import { composeCvaFn, composeShouldForwardProps, getDisplayName, serializeSplitStyles, splitJsxProps } from './helper';
|
|
4
|
+
import { isCssProperty } from './is-valid-prop';
|
|
5
|
+
|
|
6
|
+
function styledFn(BaseComponent, recipeOrConfig = {}, options = {}) {
|
|
7
|
+
const recipeFn = recipeOrConfig.__cva__ || recipeOrConfig.__recipe__ ? recipeOrConfig : cva(recipeOrConfig)
|
|
8
|
+
const composedRecipeFn = composeCvaFn(BaseComponent.__cva__, recipeFn)
|
|
9
|
+
const getRaw = composedRecipeFn.__memoizedRaw__ || composedRecipeFn.raw
|
|
10
|
+
const variantKeys = composedRecipeFn.variantKeys
|
|
11
|
+
const variantSet = new Set(variantKeys)
|
|
12
|
+
const forwardFn = options.shouldForwardProp || ((prop) => !variantSet.has(prop) && !isCssProperty(prop))
|
|
13
|
+
const forwardProps = options.forwardProps
|
|
14
|
+
const forwardPropSet = forwardProps?.length ? new Set(forwardProps) : void 0
|
|
15
|
+
const shouldForwardProp = forwardPropSet
|
|
16
|
+
? (prop) => forwardPropSet.has(prop) || forwardFn(prop, variantKeys)
|
|
17
|
+
: (prop) => forwardFn(prop, variantKeys)
|
|
18
|
+
|
|
19
|
+
const dataProps = options.dataAttr && recipeOrConfig.__name__ ? { 'data-recipe': recipeOrConfig.__name__ } : {}
|
|
20
|
+
const defaultProps = Object.assign(dataProps, options.defaultProps)
|
|
21
|
+
const hasDefaultProps = Object.keys(defaultProps).length > 0
|
|
22
|
+
|
|
23
|
+
const shouldForward = composeShouldForwardProps(BaseComponent, shouldForwardProp)
|
|
24
|
+
const DefaultElement = BaseComponent.__base__ || BaseComponent
|
|
25
|
+
|
|
26
|
+
const StyledComponent = /* @__PURE__ */ forwardRef(function StyledComponent(props, ref) {
|
|
27
|
+
const Element = props.as === void 0 ? DefaultElement : props.as
|
|
28
|
+
const unstyled = props.unstyled
|
|
29
|
+
const children = props.children
|
|
30
|
+
let combinedProps = props
|
|
31
|
+
if (hasDefaultProps) {
|
|
32
|
+
const { as, unstyled, children, ...restProps } = props
|
|
33
|
+
combinedProps = Object.assign({}, defaultProps, restProps)
|
|
34
|
+
}
|
|
35
|
+
const [htmlProps, forwardedProps, variantProps, propStyles, cssStyles, elementProps] = splitJsxProps(
|
|
36
|
+
combinedProps,
|
|
37
|
+
shouldForward,
|
|
38
|
+
variantSet,
|
|
39
|
+
isCssProperty,
|
|
40
|
+
)
|
|
41
|
+
const hasStyles = propStyles || cssStyles !== void 0
|
|
42
|
+
let className
|
|
43
|
+
if (unstyled) {
|
|
44
|
+
className = cx(hasStyles && serializeSplitStyles(propStyles, cssStyles), combinedProps.className)
|
|
45
|
+
} else if (recipeOrConfig.__recipe__) {
|
|
46
|
+
const compoundVariantClasses = composedRecipeFn.__getCompoundVariantClasses__?.(variantProps)
|
|
47
|
+
className = cx(
|
|
48
|
+
composedRecipeFn(variantProps, false),
|
|
49
|
+
compoundVariantClasses,
|
|
50
|
+
hasStyles && serializeSplitStyles(propStyles, cssStyles),
|
|
51
|
+
combinedProps.className,
|
|
52
|
+
)
|
|
53
|
+
} else {
|
|
54
|
+
className = cx(
|
|
55
|
+
hasStyles ? serializeSplitStyles(propStyles, cssStyles, getRaw(variantProps)) : composedRecipeFn(variantProps),
|
|
56
|
+
combinedProps.className,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return createElement(Element, {
|
|
61
|
+
ref,
|
|
62
|
+
...forwardedProps,
|
|
63
|
+
...elementProps,
|
|
64
|
+
...htmlProps,
|
|
65
|
+
className,
|
|
66
|
+
}, children ?? combinedProps.children)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const name = getDisplayName(DefaultElement)
|
|
70
|
+
StyledComponent.displayName = `styled.${name}`
|
|
71
|
+
StyledComponent.__cva__ = composedRecipeFn
|
|
72
|
+
StyledComponent.__base__ = DefaultElement
|
|
73
|
+
StyledComponent.__shouldForwardProps__ = shouldForwardProp
|
|
74
|
+
|
|
75
|
+
return StyledComponent
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createJsxFactory() {
|
|
79
|
+
const cache = new Map()
|
|
80
|
+
return new Proxy(styledFn, {
|
|
81
|
+
apply(_, __, args) {
|
|
82
|
+
return styledFn(...args)
|
|
83
|
+
},
|
|
84
|
+
get(_, el) {
|
|
85
|
+
if (!cache.has(el)) cache.set(el, styledFn(el))
|
|
86
|
+
return cache.get(el)
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const styled = /* @__PURE__ */ createJsxFactory()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { FlexProperties } from '../patterns/flex';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface FlexProps extends FlexProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof FlexProperties> {}
|
|
7
|
+
export declare const Flex: FunctionComponent<FlexProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { flex } from '../patterns/flex';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Flex = /* @__PURE__ */ forwardRef(function Flex(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, flex.propKeys)
|
|
8
|
+
const styleProps = flex.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { FloatProperties } from '../patterns/float';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface FloatProps extends FloatProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof FloatProperties> {}
|
|
7
|
+
export declare const Float: FunctionComponent<FloatProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { float } from '../patterns/float';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Float = /* @__PURE__ */ forwardRef(function Float(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, float.propKeys)
|
|
8
|
+
const styleProps = float.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { GridItemProperties } from '../patterns/grid-item';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface GridItemProps extends GridItemProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof GridItemProperties> {}
|
|
7
|
+
export declare const GridItem: FunctionComponent<GridItemProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { gridItem } from '../patterns/grid-item';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const GridItem = /* @__PURE__ */ forwardRef(function GridItem(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, gridItem.propKeys)
|
|
8
|
+
const styleProps = gridItem.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { GridProperties } from '../patterns/grid';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface GridProps extends GridProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof GridProperties> {}
|
|
7
|
+
export declare const Grid: FunctionComponent<GridProps>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement, forwardRef } from 'react';
|
|
2
|
+
import { grid } from '../patterns/grid';
|
|
3
|
+
import { splitProps } from '../helpers';
|
|
4
|
+
import { styled } from './factory';
|
|
5
|
+
|
|
6
|
+
export const Grid = /* @__PURE__ */ forwardRef(function Grid(props, ref) {
|
|
7
|
+
const [patternProps, restProps] = splitProps(props, grid.propKeys)
|
|
8
|
+
const styleProps = grid.raw(patternProps)
|
|
9
|
+
const mergedProps = { ref, ...restProps, css: styleProps }
|
|
10
|
+
return createElement(styled["div"], mergedProps)
|
|
11
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RecipeCreatorFn } from '../types/recipe';
|
|
2
|
+
import type { SystemStyleObject } from '../types/system';
|
|
3
|
+
|
|
4
|
+
type Props = Record<string, unknown>;
|
|
5
|
+
export type ShouldForwardProp = (prop: string, variantKeys?: string[]) => boolean;
|
|
6
|
+
/** A `cva` or config recipe function, as the JSX runtime reads it. */
|
|
7
|
+
export interface JsxRecipeFn {
|
|
8
|
+
(props?: Props, withCompoundVariants?: boolean): string;
|
|
9
|
+
raw(props?: Props): SystemStyleObject;
|
|
10
|
+
merge(other: JsxRecipeFn, cvaFn: RecipeCreatorFn): JsxRecipeFn;
|
|
11
|
+
variantKeys: string[];
|
|
12
|
+
__cva__?: boolean;
|
|
13
|
+
__recipe__?: boolean;
|
|
14
|
+
__name__?: string;
|
|
15
|
+
__memoizedRaw__?: (props?: Props) => SystemStyleObject;
|
|
16
|
+
__getCompoundVariantClasses__?: (props: Props) => string;
|
|
17
|
+
}
|
|
18
|
+
/** Markers the factory sets on the components it creates. */
|
|
19
|
+
export interface StyledMarkers {
|
|
20
|
+
__cva__?: JsxRecipeFn;
|
|
21
|
+
__base__?: unknown;
|
|
22
|
+
__shouldForwardProps__?: ShouldForwardProp;
|
|
23
|
+
}
|
|
24
|
+
export declare const composeShouldForwardProps: (tag: StyledMarkers, shouldForwardProp: ShouldForwardProp) => ShouldForwardProp;
|
|
25
|
+
export declare const composeCvaFn: (cvaA: JsxRecipeFn | undefined, cvaB: JsxRecipeFn) => JsxRecipeFn;
|
|
26
|
+
export declare const getDisplayName: (Component: string | {
|
|
27
|
+
displayName?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
} | undefined) => string;
|
|
30
|
+
export type SplitJsxProps = [htmlProps: Props | undefined, forwardedProps: Props | undefined, variantProps: Props, propStyles: SystemStyleObject | undefined, cssStyles: SystemStyleObject | undefined, elementProps: Props | undefined];
|
|
31
|
+
export declare function splitJsxProps(props: Props, shouldForwardProp: (prop: string) => boolean, variantSet: Set<string>, isCssProperty: (prop: string) => boolean, skipClass?: boolean): SplitJsxProps;
|
|
32
|
+
export declare function serializeSplitStyles(propStyles: SystemStyleObject | undefined, cssStyles: SystemStyleObject | undefined, baseStyles?: SystemStyleObject): string;
|
|
33
|
+
export declare function splitStyleProps(styleProps: Props): [propStyles: SystemStyleObject | undefined, cssStyles: SystemStyleObject | undefined];
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { css, cva } from '../css/index';
|
|
2
|
+
|
|
3
|
+
export const composeShouldForwardProps = (tag, shouldForwardProp) => {
|
|
4
|
+
if (!tag.__shouldForwardProps__ || !shouldForwardProp) return shouldForwardProp
|
|
5
|
+
return (prop) => tag.__shouldForwardProps__(prop) && shouldForwardProp(prop)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const composeCvaFn = (cvaA, cvaB) => {
|
|
9
|
+
if (cvaA && !cvaB) return cvaA
|
|
10
|
+
if (!cvaA && cvaB) return cvaB
|
|
11
|
+
if ((cvaA.__cva__ && cvaB.__cva__) || (cvaA.__recipe__ && cvaB.__recipe__)) return cvaA.merge(cvaB, cva)
|
|
12
|
+
const error = new TypeError('Cannot merge cva with recipe. Please use either cva or recipe.')
|
|
13
|
+
TypeError.captureStackTrace?.(error)
|
|
14
|
+
throw error
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getDisplayName = (Component) => {
|
|
18
|
+
if (typeof Component === 'string') return Component
|
|
19
|
+
return Component?.displayName || Component?.name || 'Component'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const htmlPropsMap = {
|
|
23
|
+
htmlWidth: 'width',
|
|
24
|
+
htmlHeight: 'height',
|
|
25
|
+
htmlTranslate: 'translate',
|
|
26
|
+
htmlContent: 'content',
|
|
27
|
+
}
|
|
28
|
+
const hasOwn = Object.prototype.hasOwnProperty
|
|
29
|
+
|
|
30
|
+
export function splitJsxProps(props, shouldForwardProp, variantSet, isCssProperty, skipClass) {
|
|
31
|
+
let htmlProps
|
|
32
|
+
let forwardedProps
|
|
33
|
+
let variantProps
|
|
34
|
+
let propStyles
|
|
35
|
+
let cssStyles
|
|
36
|
+
let elementProps
|
|
37
|
+
const keys = Object.keys(props)
|
|
38
|
+
for (let i = 0; i < keys.length; i++) {
|
|
39
|
+
const key = keys[i]
|
|
40
|
+
const value = props[key]
|
|
41
|
+
if (value === void 0) continue
|
|
42
|
+
if (key === 'className' || (skipClass && key === 'class') || key === 'as' || key === 'unstyled' || key === 'children') continue
|
|
43
|
+
if (hasOwn.call(htmlPropsMap, key)) {
|
|
44
|
+
htmlProps ||= Object.create(null)
|
|
45
|
+
htmlProps[htmlPropsMap[key]] = value
|
|
46
|
+
} else if (shouldForwardProp(key)) {
|
|
47
|
+
forwardedProps ||= Object.create(null)
|
|
48
|
+
forwardedProps[key] = value
|
|
49
|
+
} else if (variantSet.has(key)) {
|
|
50
|
+
variantProps ||= Object.create(null)
|
|
51
|
+
variantProps[key] = value
|
|
52
|
+
} else if (key === 'css') {
|
|
53
|
+
cssStyles = value
|
|
54
|
+
} else if (isCssProperty(key)) {
|
|
55
|
+
(propStyles ||= {})[key] = value
|
|
56
|
+
} else {
|
|
57
|
+
elementProps ||= Object.create(null)
|
|
58
|
+
elementProps[key] = value
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [htmlProps, forwardedProps, variantProps || {}, propStyles, cssStyles, elementProps]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function serializeSplitStyles(propStyles, cssStyles, baseStyles) {
|
|
65
|
+
if (baseStyles !== void 0) {
|
|
66
|
+
return propStyles ? cssStyles !== void 0 ? css(baseStyles, propStyles, cssStyles) : css(baseStyles, propStyles) : css(baseStyles, cssStyles)
|
|
67
|
+
}
|
|
68
|
+
return propStyles ? cssStyles !== void 0 ? css(propStyles, cssStyles) : css(propStyles) : css(cssStyles)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function splitStyleProps(styleProps) {
|
|
72
|
+
let propStyles
|
|
73
|
+
let cssStyles
|
|
74
|
+
const keys = Object.keys(styleProps)
|
|
75
|
+
for (let i = 0; i < keys.length; i++) {
|
|
76
|
+
const key = keys[i]
|
|
77
|
+
const value = styleProps[key]
|
|
78
|
+
if (value === void 0) continue
|
|
79
|
+
if (key === 'css') cssStyles = value
|
|
80
|
+
else (propStyles ||= {})[key] = value
|
|
81
|
+
}
|
|
82
|
+
return [propStyles, cssStyles]
|
|
83
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'react';
|
|
2
|
+
import type { HstackProperties } from '../patterns/hstack';
|
|
3
|
+
import type { HTMLStyledProps } from '../types/jsx';
|
|
4
|
+
import type { DistributiveOmit } from '../types/system';
|
|
5
|
+
|
|
6
|
+
export interface HstackProps extends HstackProperties, DistributiveOmit<HTMLStyledProps<'div'>, keyof HstackProperties> {}
|
|
7
|
+
export declare const HStack: FunctionComponent<HstackProps>;
|