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