components-test-pb 0.2.6 → 0.2.7
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/index.d.ts +1 -4
- package/dist/components/index.js +1 -3
- package/dist/components/src/Button/Button.d.ts +3 -0
- package/dist/components/{Button/src → src/Button}/Button.js +0 -2
- package/dist/components/src/Button/Button.types.d.ts +11 -0
- package/dist/components/src/Button/index.d.ts +5 -0
- package/dist/components/{Button/src → src/Button}/index.js +2 -2
- package/dist/components/{Button/src → src/Button}/renderButton.d.ts +1 -1
- package/dist/components/{Button/src → src/Button}/renderButton.js +1 -1
- package/dist/components/src/Button/useButton.js +15 -0
- package/dist/components/{Button/src → src/Button}/useButtonStyles.styles.d.ts +2 -2
- package/dist/components/src/Button/useButtonStyles.styles.js +31 -0
- package/dist/components/src/Text/Text.d.ts +3 -0
- package/dist/components/{Text → src/Text}/Text.types.d.ts +2 -8
- package/dist/components/src/Text/index.d.ts +5 -0
- package/dist/components/{Text → src/Text}/index.js +2 -2
- package/dist/components/{Text → src/Text}/renderText.d.ts +1 -1
- package/dist/components/{Text → src/Text}/renderText.js +2 -2
- package/dist/components/src/Text/useText.js +14 -0
- package/dist/components/{Text → src/Text}/useTextStyles.styles.d.ts +1 -1
- package/dist/components/src/Text/useTextStyles.styles.js +41 -0
- package/dist/components/src/index.d.ts +4 -0
- package/dist/components/src/index.js +2 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.js +3 -4
- package/dist/utilities/index.d.ts +2 -2
- package/dist/utilities/index.js +1 -1
- package/dist/utilities/src/compose/assertSlots.d.ts +9 -0
- package/dist/utilities/src/compose/assertSlots.js +24 -9
- package/dist/utilities/src/compose/getIntrinsicElementProps.d.ts +3 -2
- package/dist/utilities/src/compose/getIntrinsicElementProps.js +46 -45
- package/dist/utilities/src/compose/index.d.ts +1 -1
- package/dist/utilities/src/compose/slot.d.ts +19 -8
- package/dist/utilities/src/compose/slot.js +23 -14
- package/dist/utilities/src/compose/types.d.ts +1 -1
- package/dist/utilities/src/index.d.ts +1 -3
- package/dist/utilities/src/index.js +0 -1
- package/package.json +1 -1
- package/src/components/index.ts +1 -35
- package/src/components/{Button/src → src/Button}/Button.tsx +10 -10
- package/src/components/src/Button/Button.types.ts +23 -0
- package/src/components/src/Button/index.ts +5 -0
- package/src/components/{Button/src → src/Button}/renderButton.tsx +4 -4
- package/src/components/src/Button/useButton.ts +24 -0
- package/src/components/src/Button/useButtonStyles.styles.ts +59 -0
- package/src/components/{Text → src/Text}/Text.tsx +13 -10
- package/src/components/{Text → src/Text}/Text.types.ts +2 -15
- package/src/components/src/Text/index.ts +5 -0
- package/src/components/src/Text/renderText.tsx +9 -0
- package/src/components/src/Text/useText.ts +23 -0
- package/src/components/src/Text/useTextStyles.styles.ts +62 -0
- package/src/components/src/index.ts +5 -0
- package/src/index.ts +9 -43
- package/src/utilities/index.ts +3 -9
- package/src/utilities/src/compose/assertSlots.ts +31 -13
- package/src/utilities/src/compose/getIntrinsicElementProps.ts +66 -67
- package/src/utilities/src/compose/index.ts +5 -5
- package/src/utilities/src/compose/slot.ts +53 -49
- package/src/utilities/src/compose/types.ts +157 -120
- package/src/utilities/src/index.ts +2 -13
- package/dist/components/Button/src/Button.d.ts +0 -2
- package/dist/components/Button/src/Button.types.d.ts +0 -17
- package/dist/components/Button/src/index.d.ts +0 -5
- package/dist/components/Button/src/useButton.js +0 -14
- package/dist/components/Button/src/useButtonStyles.styles.js +0 -143
- package/dist/components/Text/Text.d.ts +0 -2
- package/dist/components/Text/index.d.ts +0 -5
- package/dist/components/Text/useText.js +0 -19
- package/dist/components/Text/useTextStyles.styles.js +0 -71
- package/dist/theme/defaultTheme.d.ts +0 -2
- package/dist/theme/defaultTheme.js +0 -139
- package/dist/theme/index.d.ts +0 -4
- package/dist/theme/index.js +0 -3
- package/dist/theme/themeToCSS.d.ts +0 -3
- package/dist/theme/themeToCSS.js +0 -21
- package/dist/theme/tokens.d.ts +0 -2
- package/dist/theme/tokens.js +0 -2
- package/dist/theme/types.d.ts +0 -121
- package/dist/theme/types.js +0 -1
- package/dist/utilities/src/ARIA/index.d.ts +0 -2
- package/dist/utilities/src/ARIA/index.js +0 -1
- package/dist/utilities/src/ARIA/types.d.ts +0 -18
- package/dist/utilities/src/ARIA/types.js +0 -1
- package/dist/utilities/src/ARIA/useARIAButtonProps.d.ts +0 -2
- package/dist/utilities/src/ARIA/useARIAButtonProps.js +0 -61
- package/src/components/Button/src/Button.types.ts +0 -32
- package/src/components/Button/src/index.ts +0 -12
- package/src/components/Button/src/useButton.ts +0 -25
- package/src/components/Button/src/useButtonStyles.styles.ts +0 -194
- package/src/components/Text/index.ts +0 -9
- package/src/components/Text/renderText.tsx +0 -13
- package/src/components/Text/useText.ts +0 -25
- package/src/components/Text/useTextStyles.styles.ts +0 -100
- package/src/theme/defaultTheme.ts +0 -158
- package/src/theme/index.ts +0 -4
- package/src/theme/themeToCSS.ts +0 -27
- package/src/theme/tokens.ts +0 -6
- package/src/theme/types.ts +0 -156
- package/src/utilities/src/ARIA/index.ts +0 -11
- package/src/utilities/src/ARIA/types.ts +0 -58
- package/src/utilities/src/ARIA/useARIAButtonProps.ts +0 -74
- package/dist/components/{Button/src → src/Button}/Button.types.js +0 -0
- package/dist/components/{Button/src → src/Button}/useButton.d.ts +0 -0
- package/dist/components/{Text → src/Text}/Text.js +1 -1
- /package/dist/components/{Text → src/Text}/Text.types.js +0 -0
- /package/dist/components/{Text → src/Text}/useText.d.ts +0 -0
|
@@ -1,4 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { Button, useButton, renderButton, useButtonStyles, buttonClassNames, } from './Button/src';
|
|
3
|
-
export type { TextSlots, TextProps, TextState, } from './Text';
|
|
4
|
-
export { Text, useText, renderText, useTextStyles, textClassNames, } from './Text';
|
|
1
|
+
export * from './src';
|
package/dist/components/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { useButton } from './useButton';
|
|
2
|
-
import { useButtonStyles } from './useButtonStyles.styles';
|
|
3
2
|
import { renderButton } from './renderButton';
|
|
4
3
|
export const Button = (props) => {
|
|
5
4
|
const state = useButton(props);
|
|
6
|
-
useButtonStyles(state);
|
|
7
5
|
return renderButton(state);
|
|
8
6
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComponentProps, ComponentState, Slot } from '../../../utilities';
|
|
2
|
+
export type ButtonSlots = {
|
|
3
|
+
root: NonNullable<Slot<'a'>>;
|
|
4
|
+
};
|
|
5
|
+
export type ButtonProps = ComponentProps<ButtonSlots> & {
|
|
6
|
+
appearance?: 'primary' | 'secondary' | 'ghost';
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
shape?: 'rounded' | 'circular' | 'square';
|
|
9
|
+
size?: 'small' | 'medium' | 'large';
|
|
10
|
+
};
|
|
11
|
+
export type ButtonState = ComponentState<ButtonSlots> & Required<Pick<ButtonProps, 'appearance' | 'disabled' | 'shape' | 'size'>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Button } from './Button';
|
|
2
|
+
export type { ButtonProps, ButtonSlots, ButtonState } from './Button.types';
|
|
3
|
+
export { renderButton } from './renderButton';
|
|
4
|
+
export { useButton } from './useButton';
|
|
5
|
+
export { buttonClassNames, useButtonStyles } from './useButtonStyles.styles';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Button } from './Button';
|
|
2
|
-
export { useButton } from './useButton';
|
|
3
2
|
export { renderButton } from './renderButton';
|
|
4
|
-
export {
|
|
3
|
+
export { useButton } from './useButton';
|
|
4
|
+
export { buttonClassNames, useButtonStyles } from './useButtonStyles.styles';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "jsx-framework-test-pb/jsx-runtime";
|
|
2
|
-
import { assertSlots } from '../../../utilities
|
|
2
|
+
import { assertSlots } from '../../../utilities';
|
|
3
3
|
export const renderButton = (state) => {
|
|
4
4
|
assertSlots(state);
|
|
5
5
|
return (_jsx(state.root, { children: state.root.children }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getIntrinsicElementProps, slot } from '../../../utilities';
|
|
2
|
+
export const useButton = (props) => {
|
|
3
|
+
const { appearance, disabled, shape, size } = props;
|
|
4
|
+
const state = {
|
|
5
|
+
appearance: appearance ?? 'secondary',
|
|
6
|
+
disabled: disabled ?? false,
|
|
7
|
+
shape: shape ?? 'rounded',
|
|
8
|
+
size: size ?? 'medium',
|
|
9
|
+
components: { root: 'a' },
|
|
10
|
+
root: slot.always(getIntrinsicElementProps('a', {
|
|
11
|
+
...props
|
|
12
|
+
}), { elementType: 'a' }),
|
|
13
|
+
};
|
|
14
|
+
return state;
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SlotClassNames } from '../../../utilities';
|
|
2
|
-
import { ButtonSlots, ButtonState } from './Button.types';
|
|
1
|
+
import type { SlotClassNames } from '../../../utilities';
|
|
2
|
+
import type { ButtonSlots, ButtonState } from './Button.types';
|
|
3
3
|
export declare const buttonClassNames: SlotClassNames<ButtonSlots>;
|
|
4
4
|
export declare const useButtonStyles: (state: ButtonState) => ButtonState;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { makeResetStyles, makeStyles, mergeClasses } from 'css-engine-test-pb';
|
|
2
|
+
import { textClassNames } from '../Text';
|
|
3
|
+
export const buttonClassNames = {
|
|
4
|
+
root: 'c-button'
|
|
5
|
+
};
|
|
6
|
+
const useResetStyles = makeResetStyles({});
|
|
7
|
+
const useVariationStyles = makeStyles({
|
|
8
|
+
primary: {},
|
|
9
|
+
secondary: {},
|
|
10
|
+
ghost: {},
|
|
11
|
+
circular: {},
|
|
12
|
+
rounded: {},
|
|
13
|
+
square: {},
|
|
14
|
+
small: {},
|
|
15
|
+
medium: {},
|
|
16
|
+
large: {}
|
|
17
|
+
});
|
|
18
|
+
const useDisabledStyles = makeStyles({
|
|
19
|
+
base: {},
|
|
20
|
+
primary: {},
|
|
21
|
+
secondary: {},
|
|
22
|
+
ghost: {}
|
|
23
|
+
});
|
|
24
|
+
export const useButtonStyles = (state) => {
|
|
25
|
+
const resetStyles = useResetStyles();
|
|
26
|
+
const variationStyles = useVariationStyles();
|
|
27
|
+
const disabledStyles = useDisabledStyles();
|
|
28
|
+
const { appearance, disabled, shape, size } = state;
|
|
29
|
+
state.root.className = mergeClasses(textClassNames.root, resetStyles, appearance && variationStyles[appearance], variationStyles[shape], variationStyles[size], disabled && disabledStyles.base, appearance && disabled && disabledStyles[appearance], state.root.className);
|
|
30
|
+
return state;
|
|
31
|
+
};
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import type { ComponentProps, ComponentState, Slot } from '
|
|
1
|
+
import type { ComponentProps, ComponentState, Slot } from '../../../utilities';
|
|
2
2
|
export type TextSlots = {
|
|
3
3
|
root: Slot<'span', 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'pre' | 'strong' | 'b' | 'em' | 'i'>;
|
|
4
4
|
};
|
|
5
5
|
export type TextProps = ComponentProps<TextSlots> & {
|
|
6
6
|
font?: 'base' | 'monospace' | 'numeric';
|
|
7
|
-
italic?: boolean;
|
|
8
7
|
size?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000;
|
|
9
|
-
strikethrough?: boolean;
|
|
10
|
-
truncate?: boolean;
|
|
11
|
-
underline?: boolean;
|
|
12
8
|
weight?: 'regular' | 'medium' | 'semibold' | 'bold';
|
|
13
|
-
wrap?: boolean;
|
|
14
9
|
};
|
|
15
|
-
export type
|
|
16
|
-
export type TextState = ComponentState<TextSlots> & Required<Pick<TextProps, 'font' | 'italic' | 'size' | 'strikethrough' | 'truncate' | 'underline' | 'weight' | 'wrap'>>;
|
|
10
|
+
export type TextState = ComponentState<TextSlots> & Required<Pick<TextProps, 'font' | 'size' | 'weight'>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Text } from './Text';
|
|
2
|
-
export { useText } from './useText';
|
|
3
2
|
export { renderText } from './renderText';
|
|
4
|
-
export {
|
|
3
|
+
export { useText } from './useText';
|
|
4
|
+
export { textClassNames, useTextStyles } from './useTextStyles.styles';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "jsx-framework-test-pb/jsx-runtime";
|
|
2
|
-
import { assertSlots } from '
|
|
2
|
+
import { assertSlots } from '../../../utilities';
|
|
3
3
|
export const renderText = (state) => {
|
|
4
4
|
assertSlots(state);
|
|
5
|
-
return
|
|
5
|
+
return _jsx(state.root, {});
|
|
6
6
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getIntrinsicElementProps, slot } from '../../../utilities';
|
|
2
|
+
export const useText = (props) => {
|
|
3
|
+
const { font, size, weight } = props;
|
|
4
|
+
const state = {
|
|
5
|
+
font: font ?? 'base',
|
|
6
|
+
size: size ?? 300,
|
|
7
|
+
weight: weight ?? 'regular',
|
|
8
|
+
components: { root: 'span' },
|
|
9
|
+
root: slot.always(getIntrinsicElementProps('span', {
|
|
10
|
+
...props
|
|
11
|
+
}), { elementType: 'span' })
|
|
12
|
+
};
|
|
13
|
+
return state;
|
|
14
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SlotClassNames } from '
|
|
1
|
+
import type { SlotClassNames } from '../../../utilities';
|
|
2
2
|
import type { TextSlots, TextState } from './Text.types';
|
|
3
3
|
export declare const textClassNames: SlotClassNames<TextSlots>;
|
|
4
4
|
export declare const useTextStyles: (state: TextState) => TextState;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { makeResetStyles, makeStyles, mergeClasses } from 'css-engine-test-pb';
|
|
2
|
+
export const textClassNames = {
|
|
3
|
+
root: 'c-text'
|
|
4
|
+
};
|
|
5
|
+
const useResetStyles = makeResetStyles({
|
|
6
|
+
fontFamily: 'Neue Montreal',
|
|
7
|
+
fontSize: '14px',
|
|
8
|
+
lineHeight: '20px',
|
|
9
|
+
fontWeight: 450,
|
|
10
|
+
textAlign: 'start',
|
|
11
|
+
display: 'inline',
|
|
12
|
+
whiteSpace: 'normal',
|
|
13
|
+
overflow: 'visible',
|
|
14
|
+
textOverflow: 'clip'
|
|
15
|
+
});
|
|
16
|
+
const useVariationStyles = makeStyles({
|
|
17
|
+
base: {},
|
|
18
|
+
monospace: {},
|
|
19
|
+
numeric: {},
|
|
20
|
+
100: {},
|
|
21
|
+
200: {},
|
|
22
|
+
300: {},
|
|
23
|
+
400: {},
|
|
24
|
+
500: {},
|
|
25
|
+
600: {},
|
|
26
|
+
700: {},
|
|
27
|
+
800: {},
|
|
28
|
+
900: {},
|
|
29
|
+
1000: {},
|
|
30
|
+
regular: {},
|
|
31
|
+
medium: {},
|
|
32
|
+
semibold: {},
|
|
33
|
+
bold: {}
|
|
34
|
+
});
|
|
35
|
+
export const useTextStyles = (state) => {
|
|
36
|
+
const resetStyles = useResetStyles();
|
|
37
|
+
const variationStyles = useVariationStyles();
|
|
38
|
+
const { font, size, weight } = state;
|
|
39
|
+
state.root.className = mergeClasses(textClassNames.root, resetStyles, variationStyles[font], variationStyles[size], variationStyles[weight], state.root.className);
|
|
40
|
+
return state;
|
|
41
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export {
|
|
7
|
-
export type { TextSlots, TextProps, TextState, } from './components';
|
|
8
|
-
export type { JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, ARIAButtonType, ARIAButtonElement, ARIAButtonElementIntersection, ARIAButtonProps, ARIAButtonSlotProps, ARIAButtonAlteredProps, ARIAButtonResultProps, } from './utilities';
|
|
1
|
+
export type { JSXElement, JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, } from './utilities';
|
|
2
|
+
export { assertSlots } from './utilities';
|
|
3
|
+
export { Button, buttonClassNames } from './components';
|
|
4
|
+
export type { ButtonProps, ButtonSlots } from './components';
|
|
5
|
+
export { Text, textClassNames } from './components';
|
|
6
|
+
export type { TextProps, TextSlots } from './components';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { assertSlots
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { Text, useText, renderText, useTextStyles, textClassNames, } from './components';
|
|
1
|
+
export { assertSlots } from './utilities';
|
|
2
|
+
export { Button, buttonClassNames } from './components';
|
|
3
|
+
export { Text, textClassNames } from './components';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export type { JSXElement, JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, } from './src';
|
|
2
|
+
export { assertSlots, getIntrinsicElementProps, slot } from './src';
|
package/dist/utilities/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { assertSlots, getIntrinsicElementProps, slot
|
|
1
|
+
export { assertSlots, getIntrinsicElementProps, slot } from './src';
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { FC } from 'jsx-framework-test-pb';
|
|
2
2
|
import type { ComponentState, SlotPropsRecord } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Asserts and transforms slot entries on `state` into callable JSX components.
|
|
5
|
+
*
|
|
6
|
+
* After calling this, each slot key (e.g. `state.root`, `state.icon`) becomes
|
|
7
|
+
* a function component that can be used directly in JSX: `<state.root />`.
|
|
8
|
+
*
|
|
9
|
+
* The component renders using the element type from `state.components[key]`
|
|
10
|
+
* and merges the resolved slot props with any props passed via JSX.
|
|
11
|
+
*/
|
|
3
12
|
export declare function assertSlots<Slots extends SlotPropsRecord>(state: ComponentState<Slots>): asserts state is ComponentState<Slots> & {
|
|
4
13
|
[K in keyof Slots]: FC<any>;
|
|
5
14
|
};
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { jsx } from 'jsx-framework-test-pb/jsx-runtime';
|
|
2
|
+
/**
|
|
3
|
+
* Asserts and transforms slot entries on `state` into callable JSX components.
|
|
4
|
+
*
|
|
5
|
+
* After calling this, each slot key (e.g. `state.root`, `state.icon`) becomes
|
|
6
|
+
* a function component that can be used directly in JSX: `<state.root />`.
|
|
7
|
+
*
|
|
8
|
+
* The component renders using the element type from `state.components[key]`
|
|
9
|
+
* and merges the resolved slot props with any props passed via JSX.
|
|
10
|
+
*/
|
|
2
11
|
export function assertSlots(state) {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const Component = components[name];
|
|
12
|
+
for (const name of Object.keys(state.components)) {
|
|
13
|
+
const elementType = state.components[name];
|
|
6
14
|
const slotProps = state[name];
|
|
7
|
-
if (slotProps
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
fn.children = slotProps.children;
|
|
12
|
-
state[name] = fn;
|
|
15
|
+
if (slotProps === undefined) {
|
|
16
|
+
// Optional slot not provided — render nothing
|
|
17
|
+
state[name] = () => null;
|
|
18
|
+
continue;
|
|
13
19
|
}
|
|
20
|
+
const { children, elementType: slotElementType, ...restProps } = slotProps;
|
|
21
|
+
const resolvedElementType = slotElementType ?? elementType;
|
|
22
|
+
state[name] = (jsxProps) => {
|
|
23
|
+
const mergedProps = { ...restProps, ...jsxProps };
|
|
24
|
+
if (children !== undefined) {
|
|
25
|
+
mergedProps.children = jsxProps?.children ?? children;
|
|
26
|
+
}
|
|
27
|
+
return jsx(resolvedElementType, mergedProps);
|
|
28
|
+
};
|
|
14
29
|
}
|
|
15
30
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { JSX } from 'jsx-framework-test-pb/jsx-runtime';
|
|
2
|
+
import type { JSXIntrinsicElementKeys } from './types';
|
|
3
|
+
export declare function getIntrinsicElementProps<Tag extends JSXIntrinsicElementKeys>(_elementType: Tag, props: Record<string, unknown>, excludedPropNames?: string[]): JSX.IntrinsicElements[Tag];
|
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
'
|
|
7
|
-
'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
|
|
14
|
-
'
|
|
15
|
-
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
'
|
|
21
|
-
|
|
22
|
-
'
|
|
23
|
-
//
|
|
24
|
-
'
|
|
25
|
-
|
|
26
|
-
'
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
|
|
30
|
-
'
|
|
31
|
-
|
|
32
|
-
'
|
|
33
|
-
|
|
34
|
-
'
|
|
35
|
-
|
|
36
|
-
'
|
|
37
|
-
|
|
1
|
+
// All valid HTML attribute names defined by the JSX framework's HTMLAttributes interfaces.
|
|
2
|
+
// aria-* and data-* are handled by prefix checks below.
|
|
3
|
+
// on* event handlers are handled by prefix check below.
|
|
4
|
+
const htmlAttributeNames = new Set([
|
|
5
|
+
// Global (HTMLAttributes)
|
|
6
|
+
'className', 'id', 'style', 'title', 'lang', 'dir', 'hidden', 'tabIndex', 'role',
|
|
7
|
+
'children', 'key', 'ref', 'as',
|
|
8
|
+
// Anchor (AnchorHTMLAttributes)
|
|
9
|
+
'href', 'target', 'rel', 'download', 'hrefLang',
|
|
10
|
+
// Button (ButtonHTMLAttributes)
|
|
11
|
+
'disabled', 'type', 'value', 'autoFocus', 'form',
|
|
12
|
+
'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget',
|
|
13
|
+
// Form (FormHTMLAttributes)
|
|
14
|
+
'action', 'method', 'encType', 'noValidate', 'autoComplete',
|
|
15
|
+
// Input (InputHTMLAttributes)
|
|
16
|
+
'accept', 'alt', 'capture', 'checked', 'max', 'maxLength', 'min', 'minLength',
|
|
17
|
+
'multiple', 'name', 'pattern', 'placeholder', 'readOnly', 'required', 'size',
|
|
18
|
+
'src', 'step',
|
|
19
|
+
// Textarea (TextareaHTMLAttributes)
|
|
20
|
+
'cols', 'rows', 'wrap',
|
|
21
|
+
// Select/Option
|
|
22
|
+
'selected', 'label',
|
|
23
|
+
// Img (ImgHTMLAttributes)
|
|
24
|
+
'crossOrigin', 'decoding', 'height', 'loading', 'sizes', 'srcSet', 'width',
|
|
25
|
+
// Media (VideoHTMLAttributes / AudioHTMLAttributes)
|
|
26
|
+
'autoPlay', 'controls', 'loop', 'muted', 'poster', 'preload',
|
|
27
|
+
// Table (TdHTMLAttributes / ThHTMLAttributes)
|
|
28
|
+
'cellPadding', 'cellSpacing', 'colSpan', 'rowSpan', 'headers', 'scope',
|
|
29
|
+
// Iframe (IframeHTMLAttributes)
|
|
30
|
+
'allow', 'allowFullScreen', 'sandbox', 'srcDoc',
|
|
31
|
+
// Label (LabelHTMLAttributes)
|
|
32
|
+
'htmlFor',
|
|
33
|
+
// SVG (SVGAttributes)
|
|
34
|
+
'viewBox', 'xmlns', 'fill', 'stroke', 'strokeWidth', 'strokeLinecap', 'strokeLinejoin',
|
|
35
|
+
// Meta (MetaHTMLAttributes) / Link (LinkHTMLAttributes)
|
|
36
|
+
'charSet', 'content', 'httpEquiv', 'media',
|
|
37
|
+
// Details / Dialog
|
|
38
|
+
'open',
|
|
38
39
|
]);
|
|
39
|
-
function
|
|
40
|
-
return nativeProps.has(key) || key.startsWith('data-') || key.startsWith('aria-');
|
|
41
|
-
}
|
|
42
|
-
export function getIntrinsicElementProps(tagName, props) {
|
|
40
|
+
export function getIntrinsicElementProps(_elementType, props, excludedPropNames) {
|
|
43
41
|
const result = {};
|
|
44
42
|
for (const key of Object.keys(props)) {
|
|
45
|
-
if (
|
|
43
|
+
if (excludedPropNames?.includes(key)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (htmlAttributeNames.has(key) ||
|
|
47
|
+
key.startsWith('on') ||
|
|
48
|
+
key.startsWith('aria-') ||
|
|
49
|
+
key.startsWith('data-')) {
|
|
46
50
|
result[key] = props[key];
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
|
-
if (!result.as) {
|
|
50
|
-
result.as = tagName;
|
|
51
|
-
}
|
|
52
53
|
return result;
|
|
53
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
export type { JSXElement, JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, } from './types';
|
|
1
2
|
export { assertSlots } from './assertSlots';
|
|
2
3
|
export { getIntrinsicElementProps } from './getIntrinsicElementProps';
|
|
3
4
|
export { slot } from './slot';
|
|
4
|
-
export type { JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, JSXElement, } from './types';
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
elementType:
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import type { FC } from 'jsx-framework-test-pb';
|
|
2
|
+
import type { JSXIntrinsicElementKeys, SlotShorthandValue, UnknownSlotProps, WithoutSlotRenderFunction } from './types';
|
|
3
|
+
type SlotOptions<Tag extends JSXIntrinsicElementKeys | FC<any>> = {
|
|
4
|
+
elementType: Tag;
|
|
5
|
+
};
|
|
7
6
|
export declare const slot: {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Resolves a slot that is always rendered. If `value` is null or undefined,
|
|
9
|
+
* returns an empty props object (the slot still renders using its element type).
|
|
10
|
+
*/
|
|
11
|
+
always<T extends UnknownSlotProps, Tag extends JSXIntrinsicElementKeys | FC<any>>(value: T | SlotShorthandValue | null | undefined, options: SlotOptions<Tag>): WithoutSlotRenderFunction<T> & (Tag extends JSXIntrinsicElementKeys ? {
|
|
12
|
+
as?: Tag;
|
|
13
|
+
} : {});
|
|
14
|
+
/**
|
|
15
|
+
* Resolves an optional slot. If `value` is null or undefined, returns undefined
|
|
16
|
+
* so that `assertSlots` skips rendering the slot entirely.
|
|
17
|
+
*/
|
|
18
|
+
optional<T extends UnknownSlotProps, Tag extends JSXIntrinsicElementKeys | FC<any>>(value: T | SlotShorthandValue | null | undefined, options: SlotOptions<Tag>): (WithoutSlotRenderFunction<T> & (Tag extends JSXIntrinsicElementKeys ? {
|
|
19
|
+
as?: Tag;
|
|
20
|
+
} : {})) | undefined;
|
|
10
21
|
};
|
|
11
22
|
export {};
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return (defaultProps ?? {});
|
|
1
|
+
const ELEMENT_TYPE = Symbol.for('uraniyum.element');
|
|
2
|
+
function resolveSlotValue(value, elementType) {
|
|
3
|
+
if (value === null || value === undefined) {
|
|
4
|
+
return { elementType };
|
|
5
|
+
}
|
|
6
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
7
|
+
return { elementType, children: value };
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
// JSX Element shorthand — wrap as children
|
|
10
|
+
if (typeof value === 'object' && value.$$typeof === ELEMENT_TYPE) {
|
|
11
|
+
return { elementType, children: value };
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
// Props object
|
|
14
|
+
return { elementType, ...value };
|
|
14
15
|
}
|
|
15
16
|
export const slot = {
|
|
17
|
+
/**
|
|
18
|
+
* Resolves a slot that is always rendered. If `value` is null or undefined,
|
|
19
|
+
* returns an empty props object (the slot still renders using its element type).
|
|
20
|
+
*/
|
|
16
21
|
always(value, options) {
|
|
17
|
-
return
|
|
22
|
+
return resolveSlotValue(value, options.elementType);
|
|
18
23
|
},
|
|
24
|
+
/**
|
|
25
|
+
* Resolves an optional slot. If `value` is null or undefined, returns undefined
|
|
26
|
+
* so that `assertSlots` skips rendering the slot entirely.
|
|
27
|
+
*/
|
|
19
28
|
optional(value, options) {
|
|
20
|
-
if (value
|
|
29
|
+
if (value === null || value === undefined) {
|
|
21
30
|
return undefined;
|
|
22
31
|
}
|
|
23
|
-
return
|
|
32
|
+
return resolveSlotValue(value, options.elementType);
|
|
24
33
|
},
|
|
25
34
|
};
|
|
@@ -8,7 +8,6 @@ type ReplaceNullWithUndefined<T> = T extends null ? undefined : T;
|
|
|
8
8
|
type EmptyIntrinsicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
|
|
9
9
|
type IntrinsicElementProps<Type extends JSXIntrinsicElementKeys> = Type extends EmptyIntrinsicElements ? PropsWithoutChildren<JSXIntrinsicElement<Type>> : JSXIntrinsicElement<Type>;
|
|
10
10
|
export type SlotRenderFunction<Props> = (Component: FC<Props> | JSXIntrinsicElementKeys, props: Omit<Props, 'as'>) => ElementChild;
|
|
11
|
-
export type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
|
|
12
11
|
export type SlotShorthandValue = Element | string | number;
|
|
13
12
|
export type UnknownSlotProps = {
|
|
14
13
|
className?: string | number;
|
|
@@ -16,6 +15,7 @@ export type UnknownSlotProps = {
|
|
|
16
15
|
as?: JSXIntrinsicElementKeys;
|
|
17
16
|
children?: ElementChild | ElementChild[] | SlotRenderFunction<any>;
|
|
18
17
|
};
|
|
18
|
+
export type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
|
|
19
19
|
type WithSlotShorthandValue<Props> = Props | ('children' extends keyof Props ? Extract<SlotShorthandValue, Props['children']> : never);
|
|
20
20
|
export type WithSlotRenderFunction<Props> = PropsWithoutChildren<Props> & {
|
|
21
21
|
children?: 'children' extends keyof Props ? Props['children'] | SlotRenderFunction<Props> : never;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
+
export type { JSXElement, JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, } from './compose';
|
|
1
2
|
export { assertSlots, getIntrinsicElementProps, slot } from './compose';
|
|
2
|
-
export { useARIAButtonProps } from './ARIA';
|
|
3
|
-
export type { JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, JSXElement, } from './compose';
|
|
4
|
-
export type { ARIAButtonType, ARIAButtonElement, ARIAButtonElementIntersection, ARIAButtonProps, ARIAButtonSlotProps, ARIAButtonAlteredProps, ARIAButtonResultProps, } from './ARIA';
|