components-test-pb 0.1.2 → 0.1.5
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/src/Button.d.ts +2 -0
- package/dist/components/Button/src/Button.js +8 -0
- package/dist/components/Button/src/Button.types.d.ts +17 -0
- package/dist/components/Button/src/index.d.ts +5 -0
- package/dist/components/Button/src/index.js +4 -0
- package/dist/components/Button/src/renderButton.d.ts +3 -0
- package/dist/components/Button/src/renderButton.js +6 -0
- package/dist/{Components/Button → components/Button/src}/useButton.d.ts +1 -1
- package/dist/components/Button/src/useButton.js +15 -0
- package/dist/{Components/Button → components/Button/src}/useButtonStyles.styles.d.ts +2 -2
- package/dist/components/Button/src/useButtonStyles.styles.js +30 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +1 -0
- package/dist/index.d.ts +4 -10
- package/dist/index.js +2 -6
- package/dist/utilities/index.d.ts +2 -2
- package/dist/utilities/index.js +1 -1
- package/dist/utilities/src/ARIA/index.d.ts +2 -0
- package/dist/utilities/src/ARIA/index.js +1 -0
- package/dist/utilities/src/ARIA/types.d.ts +18 -0
- package/dist/utilities/src/ARIA/useARIAButtonProps.d.ts +2 -0
- package/dist/utilities/src/ARIA/useARIAButtonProps.js +61 -0
- package/dist/utilities/src/compose/assertSlots.d.ts +5 -0
- package/dist/utilities/src/compose/assertSlots.js +13 -0
- package/dist/utilities/src/compose/index.d.ts +3 -0
- package/dist/utilities/src/compose/index.js +2 -0
- package/dist/utilities/src/compose/slot.d.ts +11 -0
- package/dist/utilities/src/compose/slot.js +25 -0
- package/dist/utilities/src/compose/types.d.ts +59 -0
- package/dist/utilities/src/index.d.ts +4 -0
- package/dist/utilities/src/index.js +2 -0
- package/package.json +4 -5
- package/src/components/Button/src/Button.tsx +10 -0
- package/src/components/Button/src/Button.types.ts +32 -0
- package/src/components/Button/src/index.ts +12 -0
- package/src/components/Button/src/renderButton.tsx +12 -0
- package/src/components/Button/src/useButton.ts +26 -0
- package/src/components/Button/src/useButtonStyles.styles.ts +77 -0
- package/src/components/index.ts +16 -0
- package/src/index.ts +37 -25
- package/src/utilities/index.ts +30 -2
- package/src/utilities/src/ARIA/index.ts +11 -0
- package/src/utilities/src/ARIA/types.ts +58 -0
- package/src/utilities/src/ARIA/useARIAButtonProps.ts +74 -0
- package/src/utilities/src/compose/assertSlots.ts +20 -0
- package/src/utilities/src/compose/index.ts +25 -0
- package/src/utilities/src/compose/slot.ts +49 -0
- package/src/utilities/src/compose/types.ts +120 -0
- package/src/utilities/src/index.ts +35 -0
- package/tsconfig.json +2 -2
- package/dist/Components/Button/Button.d.ts +0 -3
- package/dist/Components/Button/Button.js +0 -8
- package/dist/Components/Button/Button.types.d.ts +0 -15
- package/dist/Components/Button/index.d.ts +0 -5
- package/dist/Components/Button/index.js +0 -4
- package/dist/Components/Button/renderButton.d.ts +0 -3
- package/dist/Components/Button/renderButton.js +0 -6
- package/dist/Components/Button/useButton.js +0 -19
- package/dist/Components/Button/useButtonStyles.styles.js +0 -145
- package/dist/Components/Text/Text.d.ts +0 -3
- package/dist/Components/Text/Text.js +0 -8
- package/dist/Components/Text/Text.types.d.ts +0 -11
- package/dist/Components/Text/index.d.ts +0 -5
- package/dist/Components/Text/index.js +0 -4
- package/dist/Components/Text/renderText.d.ts +0 -3
- package/dist/Components/Text/renderText.js +0 -6
- package/dist/Components/Text/useText.d.ts +0 -2
- package/dist/Components/Text/useText.js +0 -10
- package/dist/Components/Text/useTextStyles.styles.d.ts +0 -4
- package/dist/Components/Text/useTextStyles.styles.js +0 -74
- package/dist/Theme/tokens.d.ts +0 -81
- package/dist/Theme/tokens.js +0 -80
- package/dist/Types/compose/index.d.ts +0 -1
- package/dist/Types/compose/index.js +0 -1
- package/dist/Types/compose/types.d.ts +0 -34
- package/dist/Types/utils/index.d.ts +0 -1
- package/dist/Types/utils/index.js +0 -1
- package/dist/Types/utils/types.d.ts +0 -168
- package/dist/Types/utils/types.js +0 -2
- package/dist/utilities/useARIAButtonProps.d.ts +0 -16
- package/dist/utilities/useARIAButtonProps.js +0 -75
- package/src/Components/Button/Button.tsx +0 -13
- package/src/Components/Button/Button.types.ts +0 -26
- package/src/Components/Button/index.ts +0 -11
- package/src/Components/Button/renderButton.tsx +0 -9
- package/src/Components/Button/useButton.ts +0 -27
- package/src/Components/Button/useButtonStyles.styles.ts +0 -198
- package/src/Components/Text/Text.tsx +0 -13
- package/src/Components/Text/Text.types.ts +0 -21
- package/src/Components/Text/index.ts +0 -11
- package/src/Components/Text/renderText.tsx +0 -9
- package/src/Components/Text/useText.ts +0 -15
- package/src/Components/Text/useTextStyles.styles.ts +0 -103
- package/src/Theme/tokens.ts +0 -98
- package/src/Types/compose/index.ts +0 -12
- package/src/Types/compose/types.ts +0 -87
- package/src/Types/utils/index.ts +0 -30
- package/src/Types/utils/types.ts +0 -223
- package/src/utilities/useARIAButtonProps.ts +0 -106
- /package/dist/{Components/Button → components/Button/src}/Button.types.js +0 -0
- /package/dist/{Types/compose → utilities/src/ARIA}/types.js +0 -0
- /package/dist/{Components/Text/Text.types.js → utilities/src/compose/types.js} +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useButton } from './useButton';
|
|
2
|
+
import { useButtonStyles } from './useButtonStyles.styles';
|
|
3
|
+
import { renderButton } from './renderButton';
|
|
4
|
+
export const Button = (props) => {
|
|
5
|
+
const state = useButton(props);
|
|
6
|
+
useButtonStyles(state);
|
|
7
|
+
return renderButton(state);
|
|
8
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ARIAButtonSlotProps } from '../../../utilities';
|
|
2
|
+
import type { ComponentProps, ComponentState, DistributiveOmit, Slot } from '../../../utilities';
|
|
3
|
+
export type ButtonSlots = {
|
|
4
|
+
root: NonNullable<Slot<ARIAButtonSlotProps<'a'>>>;
|
|
5
|
+
};
|
|
6
|
+
export type ButtonAppearance = 'primary' | 'secondary' | 'ghost';
|
|
7
|
+
export type ButtonShape = 'square' | 'rounded' | 'circular';
|
|
8
|
+
export type ButtonSize = 'small' | 'medium' | 'large';
|
|
9
|
+
export type ButtonProps = ComponentProps<ButtonSlots> & {
|
|
10
|
+
appearance?: ButtonAppearance;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
shape?: ButtonShape;
|
|
13
|
+
size?: ButtonSize;
|
|
14
|
+
};
|
|
15
|
+
export type ButtonBaseProps = DistributiveOmit<ButtonProps, 'appearance' | 'size' | 'shape'>;
|
|
16
|
+
export type ButtonState = ComponentState<ButtonSlots> & Required<Pick<ButtonProps, 'appearance' | 'disabled' | 'shape' | 'size'>>;
|
|
17
|
+
export type ButtonBaseState = DistributiveOmit<ButtonState, 'appearance' | 'size' | 'shape'>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Button } from './Button';
|
|
2
|
+
export { useButton } from './useButton';
|
|
3
|
+
export { renderButton } from './renderButton';
|
|
4
|
+
export { useButtonStyles, buttonClassNames } from './useButtonStyles.styles';
|
|
5
|
+
export type { ButtonSlots, ButtonAppearance, ButtonShape, ButtonSize, ButtonProps, ButtonState, } from './Button.types';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ButtonProps, ButtonState } from './Button.types
|
|
1
|
+
import type { ButtonProps, ButtonState } from './Button.types';
|
|
2
2
|
export declare const useButton: (props: ButtonProps) => ButtonState;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { slot, useARIAButtonProps } from '../../../utilities';
|
|
2
|
+
export const useButton = (props) => {
|
|
3
|
+
const { appearance = 'secondary', disabled = false, shape = 'rounded', size = 'medium', ...rest } = props;
|
|
4
|
+
const rootProps = slot.always(rest, {
|
|
5
|
+
elementType: 'button',
|
|
6
|
+
});
|
|
7
|
+
return {
|
|
8
|
+
appearance,
|
|
9
|
+
disabled,
|
|
10
|
+
shape,
|
|
11
|
+
size,
|
|
12
|
+
components: { root: 'button' },
|
|
13
|
+
root: useARIAButtonProps(rootProps.as ?? 'button', rootProps),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SlotClassNames } from '
|
|
2
|
-
import { ButtonSlots, ButtonState } from './Button.types
|
|
1
|
+
import { SlotClassNames } from '../../../utilities';
|
|
2
|
+
import { 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,30 @@
|
|
|
1
|
+
import { makeResetStyles, makeStyles, mergeClasses } from 'css-engine-test-pb';
|
|
2
|
+
export const buttonClassNames = {
|
|
3
|
+
root: 'c-button'
|
|
4
|
+
};
|
|
5
|
+
const useResetStyles = makeResetStyles({});
|
|
6
|
+
const useVariationStyles = makeStyles({
|
|
7
|
+
primary: {},
|
|
8
|
+
secondary: {},
|
|
9
|
+
ghost: {},
|
|
10
|
+
square: {},
|
|
11
|
+
rounded: {},
|
|
12
|
+
circular: {},
|
|
13
|
+
small: {},
|
|
14
|
+
medium: {},
|
|
15
|
+
large: {}
|
|
16
|
+
});
|
|
17
|
+
const useDisabledStyles = makeStyles({
|
|
18
|
+
base: {},
|
|
19
|
+
primary: {},
|
|
20
|
+
secondary: {},
|
|
21
|
+
ghost: {}
|
|
22
|
+
});
|
|
23
|
+
export const useButtonStyles = (state) => {
|
|
24
|
+
const resetStyles = useResetStyles();
|
|
25
|
+
const variationStyles = useVariationStyles();
|
|
26
|
+
const disabledStyles = useDisabledStyles();
|
|
27
|
+
const { appearance, disabled, shape, size } = state;
|
|
28
|
+
state.root.className = mergeClasses(buttonClassNames.root, resetStyles, variationStyles && variationStyles[appearance], variationStyles[size], variationStyles[shape], disabled && disabledStyles.base, appearance && disabled && disabledStyles[appearance], state.root.className);
|
|
29
|
+
return state;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Button, useButton, renderButton, useButtonStyles, buttonClassNames, } from './Button/src';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
5
|
-
export * from './Types/compose/index.js';
|
|
6
|
-
export * from './Types/utils/index.js';
|
|
7
|
-
export { useARIAButtonProps } from './utilities/index.js';
|
|
8
|
-
export type { ARIAButtonType, ARIAButtonProps, ARIAButtonResultProps } from './utilities/index.js';
|
|
9
|
-
export { Tokens } from './Theme/tokens.js';
|
|
10
|
-
export type { Tokens as TokensType } from './Theme/tokens.js';
|
|
1
|
+
export { assertSlots, slot, useARIAButtonProps } from './utilities';
|
|
2
|
+
export { Button, useButton, renderButton, useButtonStyles, buttonClassNames, } from './components';
|
|
3
|
+
export type { ButtonSlots, ButtonAppearance, ButtonShape, ButtonSize, ButtonProps, ButtonState, } from './components';
|
|
4
|
+
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';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { Button, useButton, renderButton, useButtonStyles } from './
|
|
3
|
-
export * from './Types/compose/index.js';
|
|
4
|
-
export * from './Types/utils/index.js';
|
|
5
|
-
export { useARIAButtonProps } from './utilities/index.js';
|
|
6
|
-
export { Tokens } from './Theme/tokens.js';
|
|
1
|
+
export { assertSlots, slot, useARIAButtonProps } from './utilities';
|
|
2
|
+
export { Button, useButton, renderButton, useButtonStyles, buttonClassNames, } from './components';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { useARIAButtonProps } from './
|
|
2
|
-
export type { ARIAButtonType, ARIAButtonProps, ARIAButtonResultProps } from './
|
|
1
|
+
export { assertSlots, slot, useARIAButtonProps } from './src';
|
|
2
|
+
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 './src';
|
package/dist/utilities/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useARIAButtonProps } from './
|
|
1
|
+
export { assertSlots, slot, useARIAButtonProps } from './src';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useARIAButtonProps } from './useARIAButtonProps';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DistributiveOmit, ExtractSlotProps, Slot, UnionToIntersection, JSXIntrinsicElement } from '../compose/types';
|
|
2
|
+
export type ARIAButtonType = 'button' | 'a' | 'div';
|
|
3
|
+
export type ARIAButtonElement<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = HTMLButtonElement | (AlternateAs extends 'a' ? HTMLAnchorElement : never) | (AlternateAs extends 'div' ? HTMLDivElement : never);
|
|
4
|
+
export type ARIAButtonElementIntersection<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = UnionToIntersection<ARIAButtonElement<AlternateAs>>;
|
|
5
|
+
export type ARIAButtonProps<Type extends ARIAButtonType = ARIAButtonType> = DistributiveOmit<JSXIntrinsicElement<Type>, 'children'> & {
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* When set, allows the button to be focusable even when it has been disabled.
|
|
9
|
+
* This is used in scenarios where it is important to keep a consistent tab order
|
|
10
|
+
* for screen reader and keyboard users.
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
disabledFocusable?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type ARIAButtonSlotProps<AlternateAs extends 'a' | 'div' = 'a' | 'div'> = ExtractSlotProps<Slot<'button', AlternateAs>> & Pick<ARIAButtonProps<ARIAButtonType>, 'disabled' | 'disabledFocusable'>;
|
|
17
|
+
export type ARIAButtonAlteredProps<Type extends ARIAButtonType> = (Type extends 'button' ? Pick<JSXIntrinsicElement<'button'>, 'onClick' | 'onKeyDown' | 'onKeyUp' | 'disabled' | 'aria-disabled' | 'tabIndex'> : never) | (Type extends 'a' ? Pick<JSXIntrinsicElement<'a'>, 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role' | 'href'> : never) | (Type extends 'div' ? Pick<JSXIntrinsicElement<'div'>, 'onClick' | 'onKeyDown' | 'onKeyUp' | 'aria-disabled' | 'tabIndex' | 'role'> : never);
|
|
18
|
+
export type ARIAButtonResultProps<Type extends ARIAButtonType, Props> = Props & UnionToIntersection<ARIAButtonAlteredProps<Type>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function useARIAButtonProps(type, props) {
|
|
2
|
+
const { disabled, disabledFocusable, onClick, onKeyDown, onKeyUp, ...rest } = props;
|
|
3
|
+
const isDisabled = disabled || disabledFocusable;
|
|
4
|
+
if (type === 'button') {
|
|
5
|
+
return {
|
|
6
|
+
...rest,
|
|
7
|
+
disabled: isDisabled && !disabledFocusable,
|
|
8
|
+
onClick: isDisabled
|
|
9
|
+
? (e) => {
|
|
10
|
+
e.preventDefault();
|
|
11
|
+
e.stopPropagation();
|
|
12
|
+
}
|
|
13
|
+
: onClick,
|
|
14
|
+
onKeyDown,
|
|
15
|
+
onKeyUp,
|
|
16
|
+
...(isDisabled && { 'aria-disabled': true }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// Non-native: 'a' | 'div'
|
|
20
|
+
const handleClick = isDisabled
|
|
21
|
+
? (e) => {
|
|
22
|
+
e.preventDefault();
|
|
23
|
+
e.stopPropagation();
|
|
24
|
+
}
|
|
25
|
+
: onClick;
|
|
26
|
+
const handleKeyDown = (e) => {
|
|
27
|
+
onKeyDown?.(e);
|
|
28
|
+
if (e.defaultPrevented)
|
|
29
|
+
return;
|
|
30
|
+
if (isDisabled)
|
|
31
|
+
return;
|
|
32
|
+
if (e.key === 'Enter') {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
e.currentTarget.click();
|
|
35
|
+
}
|
|
36
|
+
else if (e.key === ' ') {
|
|
37
|
+
e.preventDefault(); // Prevent scroll
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const handleKeyUp = (e) => {
|
|
41
|
+
onKeyUp?.(e);
|
|
42
|
+
if (e.defaultPrevented)
|
|
43
|
+
return;
|
|
44
|
+
if (isDisabled)
|
|
45
|
+
return;
|
|
46
|
+
if (e.key === ' ') {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
e.currentTarget.click();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...rest,
|
|
53
|
+
role: 'button',
|
|
54
|
+
tabIndex: isDisabled && !disabledFocusable ? undefined : rest.tabIndex ?? 0,
|
|
55
|
+
onClick: handleClick,
|
|
56
|
+
onKeyDown: handleKeyDown,
|
|
57
|
+
onKeyUp: handleKeyUp,
|
|
58
|
+
...(isDisabled && { 'aria-disabled': true }),
|
|
59
|
+
...(type === 'a' && isDisabled && { href: undefined }),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FC } from 'jsx-framework-test-pb';
|
|
2
|
+
import type { ComponentState, SlotPropsRecord } from './types';
|
|
3
|
+
export declare function assertSlots<Slots extends SlotPropsRecord>(state: ComponentState<Slots>): asserts state is ComponentState<Slots> & {
|
|
4
|
+
[K in keyof Slots]: FC<any>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from 'jsx-framework-test-pb/jsx-runtime';
|
|
2
|
+
export function assertSlots(state) {
|
|
3
|
+
const components = state.components;
|
|
4
|
+
for (const name of Object.keys(components)) {
|
|
5
|
+
const Component = components[name];
|
|
6
|
+
const slotProps = state[name];
|
|
7
|
+
if (slotProps != null) {
|
|
8
|
+
state[name] = (jsxProps) => {
|
|
9
|
+
return jsx(Component, { ...slotProps, ...jsxProps });
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { assertSlots } from './assertSlots';
|
|
2
|
+
export { slot } from './slot';
|
|
3
|
+
export type { JSXIntrinsicElementKeys, JSXIntrinsicElement, SlotRenderFunction, SlotPropsRecord, SlotShorthandValue, UnknownSlotProps, WithSlotRenderFunction, WithoutSlotRenderFunction, IsSingleton, AsIntrinsicElement, Slot, ExtractSlotProps, ComponentProps, ComponentState, SlotClassNames, EventData, EventHandler, DistributiveOmit, UnionToIntersection, JSXElement, } from './types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SlotShorthandValue, UnknownSlotProps } from './types';
|
|
2
|
+
type SlotValue = UnknownSlotProps | SlotShorthandValue | null | undefined;
|
|
3
|
+
interface SlotOptions<Props extends UnknownSlotProps> {
|
|
4
|
+
elementType: string;
|
|
5
|
+
defaultProps?: Partial<Props>;
|
|
6
|
+
}
|
|
7
|
+
export declare const slot: {
|
|
8
|
+
always<Props extends UnknownSlotProps>(value: SlotValue, options: SlotOptions<Props>): Props;
|
|
9
|
+
optional<Props extends UnknownSlotProps>(value: SlotValue, options: SlotOptions<Props>): Props | undefined;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isElement } from 'jsx-framework-test-pb';
|
|
2
|
+
function isShorthand(value) {
|
|
3
|
+
return typeof value === 'string' || typeof value === 'number' || isElement(value);
|
|
4
|
+
}
|
|
5
|
+
function resolveSlot(value, options) {
|
|
6
|
+
const { defaultProps } = options;
|
|
7
|
+
if (value == null) {
|
|
8
|
+
return (defaultProps ?? {});
|
|
9
|
+
}
|
|
10
|
+
if (isShorthand(value)) {
|
|
11
|
+
return { ...defaultProps, children: value };
|
|
12
|
+
}
|
|
13
|
+
return { ...defaultProps, ...value };
|
|
14
|
+
}
|
|
15
|
+
export const slot = {
|
|
16
|
+
always(value, options) {
|
|
17
|
+
return resolveSlot(value, options);
|
|
18
|
+
},
|
|
19
|
+
optional(value, options) {
|
|
20
|
+
if (value == null) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return resolveSlot(value, options);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { JSX } from 'jsx-framework-test-pb/jsx-runtime';
|
|
2
|
+
import type { Element, ElementChild, FC, ValidElement } from 'jsx-framework-test-pb';
|
|
3
|
+
export type JSXElement = ValidElement;
|
|
4
|
+
export type JSXIntrinsicElementKeys = keyof JSX.IntrinsicElements;
|
|
5
|
+
export type JSXIntrinsicElement<K extends JSXIntrinsicElementKeys> = JSX.IntrinsicElements[K];
|
|
6
|
+
type PropsWithoutChildren<P> = Omit<P, 'children'>;
|
|
7
|
+
type ReplaceNullWithUndefined<T> = T extends null ? undefined : T;
|
|
8
|
+
type EmptyIntrinsicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
|
|
9
|
+
type IntrinsicElementProps<Type extends JSXIntrinsicElementKeys> = Type extends EmptyIntrinsicElements ? PropsWithoutChildren<JSXIntrinsicElement<Type>> : JSXIntrinsicElement<Type>;
|
|
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
|
+
export type SlotShorthandValue = Element | string | number;
|
|
13
|
+
export type UnknownSlotProps = {
|
|
14
|
+
className?: string | number;
|
|
15
|
+
style?: Record<string, string | number>;
|
|
16
|
+
as?: JSXIntrinsicElementKeys;
|
|
17
|
+
children?: ElementChild | ElementChild[] | SlotRenderFunction<any>;
|
|
18
|
+
};
|
|
19
|
+
type WithSlotShorthandValue<Props> = Props | ('children' extends keyof Props ? Extract<SlotShorthandValue, Props['children']> : never);
|
|
20
|
+
export type WithSlotRenderFunction<Props> = PropsWithoutChildren<Props> & {
|
|
21
|
+
children?: 'children' extends keyof Props ? Props['children'] | SlotRenderFunction<Props> : never;
|
|
22
|
+
};
|
|
23
|
+
export type WithoutSlotRenderFunction<Props> = Props extends unknown ? 'children' extends keyof Props ? Omit<Props, 'children'> & {
|
|
24
|
+
children?: Exclude<Props['children'], Function>;
|
|
25
|
+
} : Props : never;
|
|
26
|
+
export type IsSingleton<T extends string> = {
|
|
27
|
+
[K in T]: Exclude<T, K> extends never ? true : false;
|
|
28
|
+
}[T];
|
|
29
|
+
export type AsIntrinsicElement<As extends JSXIntrinsicElementKeys> = {
|
|
30
|
+
as?: As;
|
|
31
|
+
};
|
|
32
|
+
export type Slot<Type extends JSXIntrinsicElementKeys | FC<any> | UnknownSlotProps, AlternateAs extends JSXIntrinsicElementKeys = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends JSXIntrinsicElementKeys ? {
|
|
33
|
+
as?: Type;
|
|
34
|
+
} & WithSlotRenderFunction<IntrinsicElementProps<Type>> : Type extends FC<infer Props> ? Props extends UnknownSlotProps ? Props : WithSlotRenderFunction<Props> : Type> | (AlternateAs extends unknown ? {
|
|
35
|
+
as: AlternateAs;
|
|
36
|
+
} & WithSlotRenderFunction<IntrinsicElementProps<AlternateAs>> : never) | null : 'Error: First parameter to Slot must not be a union of types. See documentation of Slot type.';
|
|
37
|
+
export type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
|
|
38
|
+
export type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & ExtractSlotProps<Slots[Primary]>;
|
|
39
|
+
export type ComponentState<Slots extends SlotPropsRecord> = {
|
|
40
|
+
components: {
|
|
41
|
+
[Key in keyof Slots]-?: FC<any> | JSXIntrinsicElementKeys;
|
|
42
|
+
};
|
|
43
|
+
} & {
|
|
44
|
+
[Key in keyof Slots]: ReplaceNullWithUndefined<WithoutSlotRenderFunction<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>>;
|
|
45
|
+
};
|
|
46
|
+
export type SlotClassNames<Slots> = {
|
|
47
|
+
[SlotName in keyof Slots]-?: string;
|
|
48
|
+
};
|
|
49
|
+
export type EventData<Type extends string, TEvent> = {
|
|
50
|
+
type: undefined;
|
|
51
|
+
event: Event;
|
|
52
|
+
} | {
|
|
53
|
+
type: Type;
|
|
54
|
+
event: TEvent;
|
|
55
|
+
};
|
|
56
|
+
export type EventHandler<TData extends EventData<string, unknown>> = (ev: Event, data: TData) => void;
|
|
57
|
+
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
58
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { assertSlots, 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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "components-test-pb",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,12 +17,11 @@
|
|
|
17
17
|
"prepublishOnly": "npm run build"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"jsx-framework-test-pb": "
|
|
21
|
-
"css-engine-test-pb": "latest",
|
|
20
|
+
"jsx-framework-test-pb": "^0.3.0",
|
|
22
21
|
"typescript": "^5.9.3"
|
|
23
22
|
},
|
|
24
23
|
"peerDependencies": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
24
|
+
"css-engine-test-pb": "*",
|
|
25
|
+
"jsx-framework-test-pb": "*"
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ButtonProps } from './Button.types';
|
|
2
|
+
import { useButton } from './useButton';
|
|
3
|
+
import { useButtonStyles } from './useButtonStyles.styles';
|
|
4
|
+
import { renderButton } from './renderButton';
|
|
5
|
+
|
|
6
|
+
export const Button = (props: ButtonProps) => {
|
|
7
|
+
const state = useButton(props);
|
|
8
|
+
useButtonStyles(state);
|
|
9
|
+
return renderButton(state);
|
|
10
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ARIAButtonSlotProps } from '../../../utilities';
|
|
2
|
+
import type { ComponentProps, ComponentState, DistributiveOmit, Slot } from '../../../utilities';
|
|
3
|
+
|
|
4
|
+
export type ButtonSlots = {
|
|
5
|
+
root: NonNullable<Slot<ARIAButtonSlotProps<'a'>>>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ButtonAppearance = 'primary' | 'secondary' | 'ghost';
|
|
9
|
+
export type ButtonShape = 'square' | 'rounded' | 'circular';
|
|
10
|
+
export type ButtonSize = 'small' | 'medium' | 'large';
|
|
11
|
+
|
|
12
|
+
export type ButtonProps = ComponentProps<ButtonSlots> & {
|
|
13
|
+
appearance?: ButtonAppearance;
|
|
14
|
+
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
|
|
17
|
+
shape?: ButtonShape;
|
|
18
|
+
|
|
19
|
+
size?: ButtonSize;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ButtonBaseProps = DistributiveOmit<ButtonProps, 'appearance' | 'size' | 'shape'>;
|
|
23
|
+
|
|
24
|
+
export type ButtonState = ComponentState<ButtonSlots> &
|
|
25
|
+
Required<
|
|
26
|
+
Pick<
|
|
27
|
+
ButtonProps,
|
|
28
|
+
'appearance' | 'disabled' | 'shape' | 'size'
|
|
29
|
+
>
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
export type ButtonBaseState = DistributiveOmit<ButtonState, 'appearance' | 'size' | 'shape'>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Button } from './Button';
|
|
2
|
+
export { useButton } from './useButton';
|
|
3
|
+
export { renderButton } from './renderButton';
|
|
4
|
+
export { useButtonStyles, buttonClassNames } from './useButtonStyles.styles';
|
|
5
|
+
export type {
|
|
6
|
+
ButtonSlots,
|
|
7
|
+
ButtonAppearance,
|
|
8
|
+
ButtonShape,
|
|
9
|
+
ButtonSize,
|
|
10
|
+
ButtonProps,
|
|
11
|
+
ButtonState,
|
|
12
|
+
} from './Button.types';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { assertSlots, JSXElement } from '../../../utilities/src';
|
|
2
|
+
import type { ButtonSlots, ButtonState } from './Button.types';
|
|
3
|
+
|
|
4
|
+
export const renderButton = (state: ButtonState): JSXElement => {
|
|
5
|
+
assertSlots<ButtonSlots>(state);
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<state.root>
|
|
9
|
+
{state.root.children}
|
|
10
|
+
</state.root>
|
|
11
|
+
)
|
|
12
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { slot, useARIAButtonProps } from '../../../utilities';
|
|
2
|
+
import type { ARIAButtonSlotProps } from '../../../utilities';
|
|
3
|
+
import type { ButtonProps, ButtonState } from './Button.types';
|
|
4
|
+
|
|
5
|
+
export const useButton = (props: ButtonProps): ButtonState => {
|
|
6
|
+
const {
|
|
7
|
+
appearance = 'secondary',
|
|
8
|
+
disabled = false,
|
|
9
|
+
shape = 'rounded',
|
|
10
|
+
size = 'medium',
|
|
11
|
+
...rest
|
|
12
|
+
} = props;
|
|
13
|
+
|
|
14
|
+
const rootProps = slot.always<ARIAButtonSlotProps<'a'>>(rest, {
|
|
15
|
+
elementType: 'button',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
appearance,
|
|
20
|
+
disabled,
|
|
21
|
+
shape,
|
|
22
|
+
size,
|
|
23
|
+
components: { root: 'button' },
|
|
24
|
+
root: useARIAButtonProps(rootProps.as ?? 'button', rootProps) as ButtonState['root'],
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { makeResetStyles, makeStyles, mergeClasses } from 'css-engine-test-pb';
|
|
2
|
+
import { SlotClassNames } from '../../../utilities';
|
|
3
|
+
import { ButtonSlots, ButtonState } from './Button.types';
|
|
4
|
+
|
|
5
|
+
export const buttonClassNames: SlotClassNames<ButtonSlots> = {
|
|
6
|
+
root: 'c-button'
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const useResetStyles = makeResetStyles({
|
|
10
|
+
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const useVariationStyles = makeStyles({
|
|
14
|
+
primary: {
|
|
15
|
+
|
|
16
|
+
},
|
|
17
|
+
secondary: {
|
|
18
|
+
|
|
19
|
+
},
|
|
20
|
+
ghost: {
|
|
21
|
+
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
square: {},
|
|
25
|
+
rounded: {},
|
|
26
|
+
circular: {},
|
|
27
|
+
|
|
28
|
+
small: {
|
|
29
|
+
|
|
30
|
+
},
|
|
31
|
+
medium: {},
|
|
32
|
+
large: {
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const useDisabledStyles = makeStyles({
|
|
38
|
+
base: {
|
|
39
|
+
|
|
40
|
+
},
|
|
41
|
+
primary: {
|
|
42
|
+
|
|
43
|
+
},
|
|
44
|
+
secondary: {
|
|
45
|
+
|
|
46
|
+
},
|
|
47
|
+
ghost: {
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const useButtonStyles = (state: ButtonState): ButtonState => {
|
|
53
|
+
|
|
54
|
+
const resetStyles = useResetStyles();
|
|
55
|
+
|
|
56
|
+
const variationStyles = useVariationStyles();
|
|
57
|
+
const disabledStyles = useDisabledStyles();
|
|
58
|
+
|
|
59
|
+
const { appearance, disabled, shape, size } = state;
|
|
60
|
+
|
|
61
|
+
state.root.className = mergeClasses(
|
|
62
|
+
buttonClassNames.root,
|
|
63
|
+
resetStyles,
|
|
64
|
+
|
|
65
|
+
variationStyles && variationStyles[appearance],
|
|
66
|
+
|
|
67
|
+
variationStyles[size],
|
|
68
|
+
variationStyles[shape],
|
|
69
|
+
|
|
70
|
+
disabled && disabledStyles.base,
|
|
71
|
+
appearance && disabled && disabledStyles[appearance],
|
|
72
|
+
|
|
73
|
+
state.root.className
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return state;
|
|
77
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Button,
|
|
3
|
+
useButton,
|
|
4
|
+
renderButton,
|
|
5
|
+
useButtonStyles,
|
|
6
|
+
buttonClassNames,
|
|
7
|
+
} from './Button/src';
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
ButtonSlots,
|
|
11
|
+
ButtonAppearance,
|
|
12
|
+
ButtonShape,
|
|
13
|
+
ButtonSize,
|
|
14
|
+
ButtonProps,
|
|
15
|
+
ButtonState,
|
|
16
|
+
} from './Button/src';
|