@prizmui/components 0.0.7 → 0.0.8
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/dist/components/Button/useButton.d.ts.map +1 -1
- package/dist/components/Button/useButton.js +4 -5
- package/dist/components/Text/useText.d.ts.map +1 -1
- package/dist/components/Text/useText.js +3 -4
- package/dist/utilities/assertSlots.d.ts.map +1 -1
- package/dist/utilities/assertSlots.js +3 -2
- package/dist/utilities/getIntrinsicElementProps.d.ts +17 -0
- package/dist/utilities/getIntrinsicElementProps.d.ts.map +1 -0
- package/dist/utilities/getIntrinsicElementProps.js +24 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +3 -0
- package/dist/utilities/slot.d.ts +20 -0
- package/dist/utilities/slot.d.ts.map +1 -0
- package/dist/utilities/slot.js +21 -0
- package/dist/utilities/types.d.ts +4 -5
- package/dist/utilities/types.d.ts.map +1 -1
- package/dist/utilities/useARIAButton.d.ts +27 -0
- package/dist/utilities/useARIAButton.d.ts.map +1 -0
- package/dist/utilities/useARIAButton.js +54 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useButton.d.ts","sourceRoot":"","sources":["../../../src/components/Button/useButton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useButton.d.ts","sourceRoot":"","sources":["../../../src/components/Button/useButton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG/D,eAAO,MAAM,SAAS,GAAI,OAAO,WAAW,KAAG,WAoB9C,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useARIAButtonProps, slot } from '../../utilities';
|
|
1
2
|
export const useButton = (props) => {
|
|
2
3
|
const { appearance, disabled, shape, size } = props;
|
|
3
4
|
const state = {
|
|
@@ -6,11 +7,9 @@ export const useButton = (props) => {
|
|
|
6
7
|
shape: shape ?? 'rounded',
|
|
7
8
|
size: size ?? 'medium',
|
|
8
9
|
components: { root: 'button' },
|
|
9
|
-
root: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
...props
|
|
13
|
-
}
|
|
10
|
+
root: slot.always(useARIAButtonProps('button', {
|
|
11
|
+
...props,
|
|
12
|
+
}), { elementType: 'button' })
|
|
14
13
|
};
|
|
15
14
|
return state;
|
|
16
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useText.d.ts","sourceRoot":"","sources":["../../../src/components/Text/useText.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useText.d.ts","sourceRoot":"","sources":["../../../src/components/Text/useText.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,eAAO,MAAM,OAAO,GAAI,OAAO,SAAS,KAAG,SA0B1C,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getIntrinsicElementProps, slot } from '../../utilities';
|
|
1
2
|
export const useText = (props) => {
|
|
2
3
|
const { align, block, font, italic, size, strikethrough, truncate, underline, weight, wrap } = props;
|
|
3
4
|
const state = {
|
|
@@ -12,11 +13,9 @@ export const useText = (props) => {
|
|
|
12
13
|
weight: weight ?? 'regular',
|
|
13
14
|
wrap: wrap ?? true,
|
|
14
15
|
components: { root: 'span' },
|
|
15
|
-
root: {
|
|
16
|
-
elementType: 'span',
|
|
17
|
-
type: props.as,
|
|
16
|
+
root: slot.always(getIntrinsicElementProps('span', {
|
|
18
17
|
...props
|
|
19
|
-
}
|
|
18
|
+
}), { elementType: 'span' })
|
|
20
19
|
};
|
|
21
20
|
return state;
|
|
22
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertSlots.d.ts","sourceRoot":"","sources":["../../src/utilities/assertSlots.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAgB,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,eAAe,EACtD,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,GAC9B,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAAE,
|
|
1
|
+
{"version":3,"file":"assertSlots.d.ts","sourceRoot":"","sources":["../../src/utilities/assertSlots.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAgB,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,eAAe,EACtD,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,GAC9B,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAAE,CAmChG"}
|
|
@@ -26,8 +26,8 @@ import { jsx } from 'jsx-framework-test-pb/jsx-runtime';
|
|
|
26
26
|
*/
|
|
27
27
|
export function assertSlots(state) {
|
|
28
28
|
for (const slotName of Object.keys(state.components)) {
|
|
29
|
-
const Component = state.components[slotName];
|
|
30
29
|
const slotProps = state[slotName];
|
|
30
|
+
const Component = slotProps?.elementType ?? state.components[slotName];
|
|
31
31
|
if (Component === null || Component === undefined) {
|
|
32
32
|
throw new Error(`assertSlots: slot "${slotName}" has no component in state.components. ` +
|
|
33
33
|
`Make sure every slot is assigned in the use* hook.`);
|
|
@@ -41,8 +41,9 @@ export function assertSlots(state) {
|
|
|
41
41
|
// <state.root>{someVar}</state.root> even when someVar is undefined.
|
|
42
42
|
const fn = (extraProps = {}) => {
|
|
43
43
|
const { children: explicitChildren, ...otherExtra } = extraProps;
|
|
44
|
+
const { elementType: _et, type: _t, as: _as, ...domProps } = slotProps;
|
|
44
45
|
return jsx(Component, {
|
|
45
|
-
...
|
|
46
|
+
...domProps,
|
|
46
47
|
...otherExtra,
|
|
47
48
|
...(explicitChildren !== undefined && { children: explicitChildren }),
|
|
48
49
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IntrinsicElementTag } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a clean prop object for an intrinsic element slot:
|
|
4
|
+
* - Strips `as` so it never leaks to the DOM
|
|
5
|
+
* - Resolves `elementType` to `props.as ?? defaultAs` so `assertSlots` renders
|
|
6
|
+
* the correct element when the consumer swaps it via `as`
|
|
7
|
+
* - Strips any additionally excluded prop names (component-specific props with
|
|
8
|
+
* no DOM equivalent: `appearance`, `shape`, `size`, …)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* root: slot.always(
|
|
12
|
+
* getIntrinsicElementProps('span', { ...props }),
|
|
13
|
+
* { elementType: 'span' }
|
|
14
|
+
* )
|
|
15
|
+
*/
|
|
16
|
+
export declare function getIntrinsicElementProps<TAs extends IntrinsicElementTag>(defaultAs: TAs, props: Record<string, unknown>, excludedPropNames?: readonly string[]): Record<string, unknown>;
|
|
17
|
+
//# sourceMappingURL=getIntrinsicElementProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntrinsicElementProps.d.ts","sourceRoot":"","sources":["../../src/utilities/getIntrinsicElementProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,SAAS,mBAAmB,EACpE,SAAS,EAAE,GAAG,EACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,GACtC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a clean prop object for an intrinsic element slot:
|
|
3
|
+
* - Strips `as` so it never leaks to the DOM
|
|
4
|
+
* - Resolves `elementType` to `props.as ?? defaultAs` so `assertSlots` renders
|
|
5
|
+
* the correct element when the consumer swaps it via `as`
|
|
6
|
+
* - Strips any additionally excluded prop names (component-specific props with
|
|
7
|
+
* no DOM equivalent: `appearance`, `shape`, `size`, …)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* root: slot.always(
|
|
11
|
+
* getIntrinsicElementProps('span', { ...props }),
|
|
12
|
+
* { elementType: 'span' }
|
|
13
|
+
* )
|
|
14
|
+
*/
|
|
15
|
+
export function getIntrinsicElementProps(defaultAs, props, excludedPropNames) {
|
|
16
|
+
const { as, ...result } = props;
|
|
17
|
+
result.elementType = as ?? defaultAs;
|
|
18
|
+
if (excludedPropNames) {
|
|
19
|
+
for (const key of excludedPropNames) {
|
|
20
|
+
delete result[key];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export type { DistributiveOmit, IntrinsicElementTag, IntrinsicElementProps, ElementType, IntrinsicShorthandProps, Slot, SlotPropsRecord, ComponentsRecord, ComponentProps, ComponentState, SlotClassNames, ARIAButtonSlotProps, JSXElement, } from './types';
|
|
2
2
|
export { assertSlots } from './assertSlots';
|
|
3
|
+
export { getIntrinsicElementProps } from './getIntrinsicElementProps';
|
|
4
|
+
export { useARIAButtonProps } from './useARIAButton';
|
|
5
|
+
export { slot } from './slot';
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,WAAW,EACX,uBAAuB,EACvB,IAAI,EACJ,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,UAAU,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,WAAW,EACX,uBAAuB,EACvB,IAAI,EACJ,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,UAAU,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/utilities/index.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace of slot utilities for use* hooks.
|
|
3
|
+
*/
|
|
4
|
+
export declare const slot: {
|
|
5
|
+
/**
|
|
6
|
+
* Marks a slot as always rendered (non-null) and merges in default props.
|
|
7
|
+
* The slot's own props take precedence over `defaultProps`.
|
|
8
|
+
*
|
|
9
|
+
* @param slotProps - Props returned by `getIntrinsicElementProps` or `useARIAButtonProps`
|
|
10
|
+
* @param defaultProps - Fallback props merged underneath (e.g. `{ elementType: 'button' }`)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* root: slot.always(
|
|
14
|
+
* getIntrinsicElementProps('span', { ...props }),
|
|
15
|
+
* { elementType: 'span' }
|
|
16
|
+
* )
|
|
17
|
+
*/
|
|
18
|
+
always<T extends Record<string, unknown>>(slotProps: T, defaultProps: Record<string, unknown>): T;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../src/utilities/slot.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,IAAI;IACb;;;;;;;;;;;;OAYG;WACI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,aACzB,CAAC,gBACE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACtC,CAAC;CAGP,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace of slot utilities for use* hooks.
|
|
3
|
+
*/
|
|
4
|
+
export const slot = {
|
|
5
|
+
/**
|
|
6
|
+
* Marks a slot as always rendered (non-null) and merges in default props.
|
|
7
|
+
* The slot's own props take precedence over `defaultProps`.
|
|
8
|
+
*
|
|
9
|
+
* @param slotProps - Props returned by `getIntrinsicElementProps` or `useARIAButtonProps`
|
|
10
|
+
* @param defaultProps - Fallback props merged underneath (e.g. `{ elementType: 'button' }`)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* root: slot.always(
|
|
14
|
+
* getIntrinsicElementProps('span', { ...props }),
|
|
15
|
+
* { elementType: 'span' }
|
|
16
|
+
* )
|
|
17
|
+
*/
|
|
18
|
+
always(slotProps, defaultProps) {
|
|
19
|
+
return { ...defaultProps, ...slotProps };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -89,12 +89,11 @@ export type ComponentProps<TSlots extends SlotPropsRecord, TPrimarySlot extends
|
|
|
89
89
|
export type ComponentState<TSlots extends SlotPropsRecord> = {
|
|
90
90
|
components: ComponentsRecord<TSlots>;
|
|
91
91
|
} & {
|
|
92
|
-
[K in keyof TSlots]:
|
|
93
|
-
/** The
|
|
92
|
+
[K in keyof TSlots]: (Record<string, unknown> & {
|
|
93
|
+
/** The resolved element type — set by `getIntrinsicElementProps` / `useARIAButtonProps`. */
|
|
94
94
|
elementType?: ElementType;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
95
|
+
className?: string;
|
|
96
|
+
}) | Extract<TSlots[K], null>;
|
|
98
97
|
};
|
|
99
98
|
/**
|
|
100
99
|
* Root slot props for a button-like element that can render as:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utilities/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI9D;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,CAAC,SAAS,OAAO,GAClE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACV,KAAK,CAAC;AAIZ,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,CAAC,iBAAiB,CAAC;AAE9D,0DAA0D;AAC1D,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,mBAAmB,IAC3D,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAE7B;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACnE,mBAAmB,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;AAIrC;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,uBAAuB,CAC/B,U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AAC,WAAW,SAAS,GAAG,GAAG,KAAK,GAAG,GAAG,GAAG,KAAK,IACzE,uBAAuB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAInD;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,eAAe,IAAI;KACxD,CAAC,IAAI,MAAM,MAAM,GAAG,MAAM;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ARIAButtonSlotProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves ARIA and DOM concerns for button-like elements that can render as
|
|
4
|
+
* `<button>`, `<a>`, or `<div>`, and strips `as` so it never reaches the DOM.
|
|
5
|
+
*
|
|
6
|
+
* Sets `elementType` to the resolved element (`props.as ?? defaultAs`) so
|
|
7
|
+
* `assertSlots` renders the correct tag at runtime.
|
|
8
|
+
*
|
|
9
|
+
* | Element | disabled | role | tabIndex | type |
|
|
10
|
+
* |------------|-----------------|---------------|----------|----------|
|
|
11
|
+
* | `<button>` | `disabled` | — | — | "button" |
|
|
12
|
+
* | `<a>` | `aria-disabled` | "button" | — | — |
|
|
13
|
+
* | `<div>` | `aria-disabled` | "button" | 0 | — |
|
|
14
|
+
*
|
|
15
|
+
* - `<a>` + disabled: `href` is removed to prevent navigation.
|
|
16
|
+
* - `<button>` gets `type="button"` by default to prevent form submission.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* root: slot.always(
|
|
20
|
+
* useARIAButtonProps('button', { ...props }),
|
|
21
|
+
* { elementType: 'button' }
|
|
22
|
+
* )
|
|
23
|
+
*/
|
|
24
|
+
export declare function useARIAButtonProps(defaultAs: 'button' | 'a' | 'div', props: ARIAButtonSlotProps & {
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
}): Record<string, unknown>;
|
|
27
|
+
//# sourceMappingURL=useARIAButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useARIAButton.d.ts","sourceRoot":"","sources":["../../src/utilities/useARIAButton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAC9B,SAAS,EAAE,QAAQ,GAAG,GAAG,GAAG,KAAK,EACjC,KAAK,EAAE,mBAAmB,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GACpD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmCzB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves ARIA and DOM concerns for button-like elements that can render as
|
|
3
|
+
* `<button>`, `<a>`, or `<div>`, and strips `as` so it never reaches the DOM.
|
|
4
|
+
*
|
|
5
|
+
* Sets `elementType` to the resolved element (`props.as ?? defaultAs`) so
|
|
6
|
+
* `assertSlots` renders the correct tag at runtime.
|
|
7
|
+
*
|
|
8
|
+
* | Element | disabled | role | tabIndex | type |
|
|
9
|
+
* |------------|-----------------|---------------|----------|----------|
|
|
10
|
+
* | `<button>` | `disabled` | — | — | "button" |
|
|
11
|
+
* | `<a>` | `aria-disabled` | "button" | — | — |
|
|
12
|
+
* | `<div>` | `aria-disabled` | "button" | 0 | — |
|
|
13
|
+
*
|
|
14
|
+
* - `<a>` + disabled: `href` is removed to prevent navigation.
|
|
15
|
+
* - `<button>` gets `type="button"` by default to prevent form submission.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* root: slot.always(
|
|
19
|
+
* useARIAButtonProps('button', { ...props }),
|
|
20
|
+
* { elementType: 'button' }
|
|
21
|
+
* )
|
|
22
|
+
*/
|
|
23
|
+
export function useARIAButtonProps(defaultAs, props) {
|
|
24
|
+
const as = (props.as ?? defaultAs);
|
|
25
|
+
const disabled = props.disabled;
|
|
26
|
+
const href = props.href;
|
|
27
|
+
// Strip 'as', 'disabled', 'href' — all resolved manually below
|
|
28
|
+
const { as: _as, disabled: _disabled, href: _href, ...rest } = props;
|
|
29
|
+
if (as === 'button') {
|
|
30
|
+
return {
|
|
31
|
+
type: 'button',
|
|
32
|
+
disabled: disabled || undefined,
|
|
33
|
+
...rest,
|
|
34
|
+
elementType: 'button',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (as === 'a') {
|
|
38
|
+
return {
|
|
39
|
+
role: 'button',
|
|
40
|
+
'aria-disabled': disabled || undefined,
|
|
41
|
+
href: disabled ? undefined : href,
|
|
42
|
+
...rest,
|
|
43
|
+
elementType: 'a',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// div
|
|
47
|
+
return {
|
|
48
|
+
role: 'button',
|
|
49
|
+
tabIndex: disabled ? undefined : 0,
|
|
50
|
+
'aria-disabled': disabled || undefined,
|
|
51
|
+
...rest,
|
|
52
|
+
elementType: 'div',
|
|
53
|
+
};
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prizmui/components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"calame": "0.0.6",
|
|
18
|
+
"@prizmui/tokens": "0.0.3"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"jsx-framework-test-pb": "*"
|