@westpac/ui 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/component-type.json +1 -1
- package/dist/components/badge/badge.component.d.ts +6 -3
- package/dist/components/badge/badge.component.js +3 -2
- package/dist/components/badge/badge.styles.d.ts +8 -0
- package/dist/components/badge/badge.styles.js +54 -3
- package/dist/components/badge/badge.types.d.ts +5 -0
- package/dist/components/button-group/button-group.component.d.ts +1 -1
- package/dist/components/button-group/button-group.component.js +7 -10
- package/dist/components/button-group/button-group.types.d.ts +4 -4
- package/dist/components/button-group/components/button-group-button/button-group-button.component.d.ts +1 -1
- package/dist/components/button-group/components/button-group-button/button-group-button.component.js +3 -3
- package/dist/components/button-group/components/button-group-button/button-group-button.types.d.ts +6 -1
- package/dist/components/checkbox-group/checkbox-group.component.d.ts +1 -1
- package/dist/components/checkbox-group/checkbox-group.component.js +7 -9
- package/dist/components/checkbox-group/checkbox-group.types.d.ts +2 -2
- package/dist/components/checkbox-group/components/checkbox-group-checkbox/checkbox-group-checkbox.component.d.ts +2 -1
- package/dist/components/checkbox-group/components/checkbox-group-checkbox/checkbox-group-checkbox.component.js +3 -3
- package/dist/components/checkbox-group/components/checkbox-group-checkbox/checkbox-group-checkbox.types.d.ts +5 -1
- package/dist/components/radio-group/components/radio-group-radio/radio-group-radio.component.d.ts +2 -1
- package/dist/components/radio-group/components/radio-group-radio/radio-group-radio.component.js +3 -3
- package/dist/components/radio-group/components/radio-group-radio/radio-group-radio.types.d.ts +5 -1
- package/dist/components/radio-group/radio-group.component.d.ts +1 -1
- package/dist/components/radio-group/radio-group.component.js +7 -9
- package/dist/components/radio-group/radio-group.types.d.ts +5 -5
- package/dist/css/westpac-ui.css +55 -0
- package/dist/css/westpac-ui.min.css +55 -0
- package/package.json +3 -3
- package/src/components/badge/badge.component.tsx +2 -2
- package/src/components/badge/badge.styles.ts +53 -2
- package/src/components/badge/badge.types.ts +5 -0
- package/src/components/button-group/button-group.component.tsx +6 -10
- package/src/components/button-group/button-group.types.ts +5 -4
- package/src/components/button-group/components/button-group-button/button-group-button.component.tsx +3 -3
- package/src/components/button-group/components/button-group-button/button-group-button.types.ts +6 -1
- package/src/components/checkbox-group/checkbox-group.component.tsx +8 -11
- package/src/components/checkbox-group/checkbox-group.types.ts +3 -2
- package/src/components/checkbox-group/components/checkbox-group-checkbox/checkbox-group-checkbox.component.tsx +7 -3
- package/src/components/checkbox-group/components/checkbox-group-checkbox/checkbox-group-checkbox.types.ts +5 -1
- package/src/components/radio-group/components/radio-group-radio/radio-group-radio.component.tsx +3 -3
- package/src/components/radio-group/components/radio-group-radio/radio-group-radio.types.ts +5 -1
- package/src/components/radio-group/radio-group.component.tsx +8 -11
- package/src/components/radio-group/radio-group.types.ts +6 -5
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type BadgeProps } from './badge.types.js';
|
|
3
|
-
export declare function BaseBadge({ className, tag: Tag, color, type, children, ...props }: BadgeProps, ref: any): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function BaseBadge({ className, tag: Tag, color, type, soft, children, ...props }: BadgeProps, ref: any): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export declare const Badge: React.ForwardRefExoticComponent<{
|
|
5
5
|
children?: React.ReactNode;
|
|
6
|
-
color?: "primary" | "hero" | "faint" | "success" | "info" | "warning" | "danger" | "neutral" | "danger-inverted" | "faint-inverted" | "hero-inverted" | "info-inverted" | "neutral-inverted" | "primary-inverted" | "success-inverted" | "warning-inverted" | {
|
|
7
|
-
[x: string]: "primary" | "hero" | "faint" | "success" | "info" | "warning" | "danger" | "neutral" | "danger-inverted" | "faint-inverted" | "hero-inverted" | "info-inverted" | "neutral-inverted" | "primary-inverted" | "success-inverted" | "warning-inverted" | undefined;
|
|
6
|
+
color?: "primary" | "hero" | "faint" | "success" | "info" | "warning" | "danger" | "muted" | "neutral" | "danger-inverted" | "faint-inverted" | "hero-inverted" | "info-inverted" | "neutral-inverted" | "primary-inverted" | "success-inverted" | "warning-inverted" | {
|
|
7
|
+
[x: string]: "primary" | "hero" | "faint" | "success" | "info" | "warning" | "danger" | "muted" | "neutral" | "danger-inverted" | "faint-inverted" | "hero-inverted" | "info-inverted" | "neutral-inverted" | "primary-inverted" | "success-inverted" | "warning-inverted" | undefined;
|
|
8
|
+
} | undefined;
|
|
9
|
+
soft?: boolean | {
|
|
10
|
+
[x: string]: boolean | undefined;
|
|
8
11
|
} | undefined;
|
|
9
12
|
tag?: keyof JSX.IntrinsicElements | undefined;
|
|
10
13
|
type?: "default" | "pill" | {
|
|
@@ -15,14 +15,15 @@ function _extends() {
|
|
|
15
15
|
}
|
|
16
16
|
import React, { forwardRef } from 'react';
|
|
17
17
|
import { styles } from './badge.styles.js';
|
|
18
|
-
export function BaseBadge({ className , tag: Tag = 'div' , color ='hero' , type ='default' , children , ...props }, ref) {
|
|
18
|
+
export function BaseBadge({ className , tag: Tag = 'div' , color ='hero' , type ='default' , soft =false , children , ...props }, ref) {
|
|
19
19
|
return React.createElement(Tag, _extends({}, {
|
|
20
20
|
ref
|
|
21
21
|
}, {
|
|
22
22
|
className: styles({
|
|
23
23
|
className,
|
|
24
24
|
color,
|
|
25
|
-
type
|
|
25
|
+
type,
|
|
26
|
+
soft
|
|
26
27
|
})
|
|
27
28
|
}, props), children);
|
|
28
29
|
}
|
|
@@ -5,6 +5,7 @@ export declare const styles: import("tailwind-variants").TVReturnType<{
|
|
|
5
5
|
hero: string;
|
|
6
6
|
info: string;
|
|
7
7
|
neutral: string;
|
|
8
|
+
muted: string;
|
|
8
9
|
primary: string;
|
|
9
10
|
success: string;
|
|
10
11
|
warning: string;
|
|
@@ -21,6 +22,9 @@ export declare const styles: import("tailwind-variants").TVReturnType<{
|
|
|
21
22
|
pill: string;
|
|
22
23
|
default: string;
|
|
23
24
|
};
|
|
25
|
+
soft: {
|
|
26
|
+
true: string;
|
|
27
|
+
};
|
|
24
28
|
}, undefined, "inline-block whitespace-nowrap border text-center leading-none", {
|
|
25
29
|
responsiveVariants: string[];
|
|
26
30
|
}, {
|
|
@@ -30,6 +34,7 @@ export declare const styles: import("tailwind-variants").TVReturnType<{
|
|
|
30
34
|
hero: string;
|
|
31
35
|
info: string;
|
|
32
36
|
neutral: string;
|
|
37
|
+
muted: string;
|
|
33
38
|
primary: string;
|
|
34
39
|
success: string;
|
|
35
40
|
warning: string;
|
|
@@ -46,4 +51,7 @@ export declare const styles: import("tailwind-variants").TVReturnType<{
|
|
|
46
51
|
pill: string;
|
|
47
52
|
default: string;
|
|
48
53
|
};
|
|
54
|
+
soft: {
|
|
55
|
+
true: string;
|
|
56
|
+
};
|
|
49
57
|
}, undefined>;
|
|
@@ -4,10 +4,11 @@ export const styles = tv({
|
|
|
4
4
|
variants: {
|
|
5
5
|
color: {
|
|
6
6
|
danger: 'border-danger bg-danger text-white',
|
|
7
|
-
faint: 'border-border bg-
|
|
7
|
+
faint: 'border-border bg-border text-muted',
|
|
8
8
|
hero: 'border-hero bg-hero text-white',
|
|
9
9
|
info: 'border-info bg-info text-white',
|
|
10
10
|
neutral: 'border-neutral bg-neutral text-white',
|
|
11
|
+
muted: 'border-muted bg-muted text-white',
|
|
11
12
|
primary: 'border-primary bg-primary text-white',
|
|
12
13
|
success: 'border-success bg-success text-white',
|
|
13
14
|
warning: 'border-warning bg-warning text-white',
|
|
@@ -21,10 +22,60 @@ export const styles = tv({
|
|
|
21
22
|
'warning-inverted': 'border-none bg-white text-warning'
|
|
22
23
|
},
|
|
23
24
|
type: {
|
|
24
|
-
pill: 'typography-body-10 rounded-xl px-[0.4375rem] py-[0.25rem] font-
|
|
25
|
+
pill: 'typography-body-10 rounded-xl px-[0.4375rem] py-[0.25rem] font-medium leading-none',
|
|
25
26
|
default: 'rounded-sm px-1 py-0.5 pb-[0.125rem] text-[0.75rem] leading-none'
|
|
27
|
+
},
|
|
28
|
+
soft: {
|
|
29
|
+
true: 'bg-white'
|
|
26
30
|
}
|
|
27
|
-
}
|
|
31
|
+
},
|
|
32
|
+
compoundVariants: [
|
|
33
|
+
{
|
|
34
|
+
color: 'danger',
|
|
35
|
+
soft: true,
|
|
36
|
+
className: 'text-danger'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
color: 'faint',
|
|
40
|
+
soft: true,
|
|
41
|
+
className: 'text-muted'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
color: 'hero',
|
|
45
|
+
soft: true,
|
|
46
|
+
className: 'text-hero'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
color: 'info',
|
|
50
|
+
soft: true,
|
|
51
|
+
className: 'text-info'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
color: 'neutral',
|
|
55
|
+
soft: true,
|
|
56
|
+
className: 'text-neutral'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
color: 'muted',
|
|
60
|
+
soft: true,
|
|
61
|
+
className: 'text-muted'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
color: 'primary',
|
|
65
|
+
soft: true,
|
|
66
|
+
className: 'text-primary'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
color: 'success',
|
|
70
|
+
soft: true,
|
|
71
|
+
className: 'text-success'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
color: 'warning',
|
|
75
|
+
soft: true,
|
|
76
|
+
className: 'text-warning'
|
|
77
|
+
}
|
|
78
|
+
]
|
|
28
79
|
}, {
|
|
29
80
|
responsiveVariants: [
|
|
30
81
|
'xsl',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ButtonGroupContextState, type ButtonGroupProps } from './button-group.types.js';
|
|
3
3
|
export declare const ButtonGroupContext: React.Context<ButtonGroupContextState>;
|
|
4
|
-
export declare function ButtonGroup({ className,
|
|
4
|
+
export declare function ButtonGroup({ className, buttons, label, look, size, block, errorMessage, hintMessage, ...props }: ButtonGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -13,10 +13,10 @@ function _extends() {
|
|
|
13
13
|
};
|
|
14
14
|
return _extends.apply(this, arguments);
|
|
15
15
|
}
|
|
16
|
-
import React, {
|
|
16
|
+
import React, { createContext } from 'react';
|
|
17
17
|
import { useRadioGroup } from 'react-aria';
|
|
18
18
|
import { useRadioGroupState } from 'react-stately';
|
|
19
|
-
import { ErrorMessage, Hint, Label } from '../index.js';
|
|
19
|
+
import { ButtonGroupButton, ErrorMessage, Hint, Label } from '../index.js';
|
|
20
20
|
import { styles as buttonGroupStyles } from './button-group.styles.js';
|
|
21
21
|
export const ButtonGroupContext = createContext({
|
|
22
22
|
name: '',
|
|
@@ -32,7 +32,7 @@ export const ButtonGroupContext = createContext({
|
|
|
32
32
|
look: 'hero',
|
|
33
33
|
size: 'medium'
|
|
34
34
|
});
|
|
35
|
-
export function ButtonGroup({ className ,
|
|
35
|
+
export function ButtonGroup({ className , buttons , label , look ='hero' , size ='medium' , block =false , errorMessage , hintMessage , ...props }) {
|
|
36
36
|
const state = useRadioGroupState({
|
|
37
37
|
...props,
|
|
38
38
|
label,
|
|
@@ -45,12 +45,6 @@ export function ButtonGroup({ className , children , label , look ='hero' , size
|
|
|
45
45
|
orientation: 'horizontal'
|
|
46
46
|
}, state);
|
|
47
47
|
const styles = buttonGroupStyles({});
|
|
48
|
-
const childrenToRender = children.map((child, index)=>{
|
|
49
|
-
return cloneElement(child, {
|
|
50
|
-
key: index,
|
|
51
|
-
className: 'group/buttons'
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
48
|
return React.createElement("div", _extends({
|
|
55
49
|
className: styles.base({
|
|
56
50
|
className
|
|
@@ -66,5 +60,8 @@ export function ButtonGroup({ className , children , label , look ='hero' , size
|
|
|
66
60
|
look,
|
|
67
61
|
block
|
|
68
62
|
}
|
|
69
|
-
},
|
|
63
|
+
}, buttons.map((button, index)=>React.createElement(ButtonGroupButton, _extends({
|
|
64
|
+
key: index,
|
|
65
|
+
className: "group/buttons"
|
|
66
|
+
}, button))))));
|
|
70
67
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
1
|
import { AriaRadioGroupProps } from 'react-aria';
|
|
3
2
|
import { RadioGroupState } from 'react-stately';
|
|
4
3
|
import { type ButtonProps } from '../button/index.js';
|
|
4
|
+
import { ButtonGroupButtonProps } from './components/button-group-button/button-group-button.types.js';
|
|
5
5
|
export type ButtonGroupProps = {
|
|
6
6
|
/**
|
|
7
7
|
* Sets whether buttons fill the entire box they are located in
|
|
8
8
|
*/
|
|
9
9
|
block?: boolean;
|
|
10
10
|
/**
|
|
11
|
-
* The `Button` components to render
|
|
11
|
+
* The `Button` components to render in the form of an object
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
buttons: Omit<ButtonGroupButtonProps, 'className'>[];
|
|
14
14
|
/**
|
|
15
15
|
* String to override base style
|
|
16
16
|
*/
|
|
@@ -27,7 +27,7 @@ export type ButtonGroupProps = {
|
|
|
27
27
|
* Controls look of `Button` components, can't be applied directly to `Button`
|
|
28
28
|
*/
|
|
29
29
|
look?: 'hero' | 'primary';
|
|
30
|
-
} & Omit<AriaRadioGroupProps, 'errorMessage' | 'description' | 'orientation'> & Pick<ButtonProps, 'size'>;
|
|
30
|
+
} & Omit<AriaRadioGroupProps, 'errorMessage' | 'description' | 'orientation' | 'children'> & Pick<ButtonProps, 'size'>;
|
|
31
31
|
export type ButtonGroupContextState = {
|
|
32
32
|
/**
|
|
33
33
|
* Sets whether buttons fill the entire box they are located in
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type ButtonGroupButtonProps } from './button-group-button.types.js';
|
|
2
|
-
export declare function ButtonGroupButton({ className,
|
|
2
|
+
export declare function ButtonGroupButton({ className, label, ...props }: ButtonGroupButtonProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/components/button-group/components/button-group-button/button-group-button.component.js
CHANGED
|
@@ -18,13 +18,13 @@ import { VisuallyHidden, useFocusRing, useRadio } from 'react-aria';
|
|
|
18
18
|
import { Button as GELButton } from '../../../button/index.js';
|
|
19
19
|
import { ButtonGroupContext } from '../../button-group.component.js';
|
|
20
20
|
import { styles as buttonStyles } from './button-group-button.styles.js';
|
|
21
|
-
export function ButtonGroupButton({ className ,
|
|
21
|
+
export function ButtonGroupButton({ className , label , ...props }) {
|
|
22
22
|
const state = useContext(ButtonGroupContext);
|
|
23
23
|
const { size , look , block } = state;
|
|
24
24
|
const ref = useRef(null);
|
|
25
25
|
const { inputProps , isSelected , isDisabled } = useRadio({
|
|
26
26
|
...props,
|
|
27
|
-
children
|
|
27
|
+
children: label
|
|
28
28
|
}, state, ref);
|
|
29
29
|
const { isFocusVisible , focusProps } = useFocusRing();
|
|
30
30
|
const styles = buttonStyles({
|
|
@@ -46,5 +46,5 @@ export function ButtonGroupButton({ className , children , ...props }) {
|
|
|
46
46
|
look: look,
|
|
47
47
|
size: size,
|
|
48
48
|
className: styles.button()
|
|
49
|
-
},
|
|
49
|
+
}, label));
|
|
50
50
|
}
|
package/dist/components/button-group/components/button-group-button/button-group-button.types.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
1
2
|
import { AriaRadioProps } from 'react-aria';
|
|
2
3
|
export type ButtonGroupButtonProps = {
|
|
3
4
|
/**
|
|
4
5
|
* `string` for overriding base style
|
|
5
6
|
*/
|
|
6
7
|
className?: string;
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Label to render
|
|
10
|
+
*/
|
|
11
|
+
label: ReactNode;
|
|
12
|
+
} & Omit<AriaRadioProps, 'children'>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type CheckboxGroupContextState, type CheckboxGroupProps } from './checkbox-group.types.js';
|
|
3
3
|
export declare const CheckboxGroupContext: React.Context<CheckboxGroupContextState>;
|
|
4
|
-
export declare function CheckboxGroup({ className,
|
|
4
|
+
export declare function CheckboxGroup({ className, checkboxes, label, orientation, showAmount, size, errorMessage, hintMessage, ...props }: CheckboxGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -13,12 +13,12 @@ function _extends() {
|
|
|
13
13
|
};
|
|
14
14
|
return _extends.apply(this, arguments);
|
|
15
15
|
}
|
|
16
|
-
import React, {
|
|
16
|
+
import React, { createContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
17
17
|
import { useCheckboxGroup, useFocusRing } from 'react-aria';
|
|
18
18
|
import { useCheckboxGroupState } from 'react-stately';
|
|
19
19
|
import { Button } from '../button/index.js';
|
|
20
20
|
import { ExpandMoreIcon } from '../icon/index.js';
|
|
21
|
-
import { ErrorMessage, Hint, Label } from '../index.js';
|
|
21
|
+
import { CheckboxGroupCheckbox, ErrorMessage, Hint, Label } from '../index.js';
|
|
22
22
|
import { styles as checkboxStyles } from './checkbox-group.styles.js';
|
|
23
23
|
export const CheckboxGroupContext = createContext({
|
|
24
24
|
orientation: 'vertical',
|
|
@@ -33,7 +33,7 @@ export const CheckboxGroupContext = createContext({
|
|
|
33
33
|
toggleValue: ()=>null,
|
|
34
34
|
validationState: 'valid'
|
|
35
35
|
});
|
|
36
|
-
export function CheckboxGroup({ className ,
|
|
36
|
+
export function CheckboxGroup({ className , checkboxes , label , orientation ='vertical' , showAmount =0 , size ='medium' , errorMessage , hintMessage , ...props }) {
|
|
37
37
|
const state = useCheckboxGroupState({
|
|
38
38
|
...props,
|
|
39
39
|
label
|
|
@@ -45,21 +45,19 @@ export function CheckboxGroup({ className , children , label , orientation ='ver
|
|
|
45
45
|
const { isFocusVisible , focusProps } = useFocusRing();
|
|
46
46
|
const [hiddenOptions, setHiddenOptions] = useState(showAmount > 0);
|
|
47
47
|
const firstNewCheckboxRef = useRef(null);
|
|
48
|
-
const revealAmount =
|
|
48
|
+
const revealAmount = checkboxes && checkboxes.length - showAmount;
|
|
49
49
|
const styles = checkboxStyles({
|
|
50
50
|
orientation,
|
|
51
51
|
isFocusVisible
|
|
52
52
|
});
|
|
53
53
|
const childrenToRender = useMemo(()=>{
|
|
54
|
-
const newChildren =
|
|
55
|
-
return cloneElement(child, {
|
|
54
|
+
const newChildren = checkboxes.map((checkbox, index)=>React.createElement(CheckboxGroupCheckbox, _extends({
|
|
56
55
|
key: index,
|
|
57
56
|
ref: index === showAmount ? firstNewCheckboxRef : null
|
|
58
|
-
});
|
|
59
|
-
});
|
|
57
|
+
}, checkbox)));
|
|
60
58
|
return hiddenOptions ? newChildren.slice(0, showAmount) : newChildren;
|
|
61
59
|
}, [
|
|
62
|
-
|
|
60
|
+
checkboxes,
|
|
63
61
|
hiddenOptions,
|
|
64
62
|
showAmount
|
|
65
63
|
]);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
1
|
import { AriaCheckboxGroupProps } from 'react-aria';
|
|
3
2
|
import { CheckboxGroupState } from 'react-stately';
|
|
4
3
|
import { HintProps } from '../index.js';
|
|
4
|
+
import { CheckboxGroupCheckboxProps } from './components/checkbox-group-checkbox/checkbox-group-checkbox.types.js';
|
|
5
5
|
export type CheckboxGroupProps = {
|
|
6
6
|
/**
|
|
7
7
|
* The `CheckboxItem` components to render
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
checkboxes: CheckboxGroupCheckboxProps[];
|
|
10
10
|
/**
|
|
11
11
|
* String to override base style
|
|
12
12
|
*/
|
|
@@ -2,4 +2,5 @@ import React from 'react';
|
|
|
2
2
|
export declare const CheckboxGroupCheckbox: React.ForwardRefExoticComponent<{
|
|
3
3
|
className?: string | undefined;
|
|
4
4
|
hint?: React.ReactNode;
|
|
5
|
-
|
|
5
|
+
label: React.ReactNode;
|
|
6
|
+
} & Omit<import("react-aria").AriaCheckboxGroupItemProps, "children" | "isIndeterminate"> & React.RefAttributes<unknown>>;
|
|
@@ -31,14 +31,14 @@ function CheckIcon({ copyrightYear ='2023' , size , ...props }) {
|
|
|
31
31
|
fill: "currentColor"
|
|
32
32
|
}));
|
|
33
33
|
}
|
|
34
|
-
function BaseCheckbox({ className , hint ,
|
|
34
|
+
function BaseCheckbox({ className , hint , label , value , ...props }, ref) {
|
|
35
35
|
const state = useContext(CheckboxGroupContext);
|
|
36
36
|
const { size , orientation } = state;
|
|
37
37
|
const localRef = useRef(null);
|
|
38
38
|
const { inputProps , isDisabled , isSelected } = useCheckboxGroupItem({
|
|
39
39
|
...props,
|
|
40
40
|
value,
|
|
41
|
-
children
|
|
41
|
+
children: label
|
|
42
42
|
}, state, localRef);
|
|
43
43
|
const { isFocusVisible , focusProps } = useFocusRing();
|
|
44
44
|
const styles = checkboxItemStyles({
|
|
@@ -64,7 +64,7 @@ function BaseCheckbox({ className , hint , children , value , ...props }, ref) {
|
|
|
64
64
|
className: styles.textWrapper()
|
|
65
65
|
}, React.createElement("span", {
|
|
66
66
|
className: styles.labelText()
|
|
67
|
-
},
|
|
67
|
+
}, label), hint && React.createElement("span", {
|
|
68
68
|
className: styles.hintText()
|
|
69
69
|
}, hint)));
|
|
70
70
|
}
|
|
@@ -9,4 +9,8 @@ export type CheckboxGroupCheckboxProps = {
|
|
|
9
9
|
* Renders hint under option, most likely a `string` but could be something else
|
|
10
10
|
*/
|
|
11
11
|
hint?: ReactNode;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Label to render
|
|
14
|
+
*/
|
|
15
|
+
label: ReactNode;
|
|
16
|
+
} & Omit<AriaCheckboxGroupItemProps, 'isIndeterminate' | 'children'>;
|
package/dist/components/radio-group/components/radio-group-radio/radio-group-radio.component.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import React from 'react';
|
|
|
2
2
|
export declare const RadioGroupRadio: React.ForwardRefExoticComponent<{
|
|
3
3
|
className?: string | undefined;
|
|
4
4
|
hint?: React.ReactNode;
|
|
5
|
-
|
|
5
|
+
label: React.ReactNode;
|
|
6
|
+
} & Omit<import("react-aria").AriaRadioProps, "children"> & React.RefAttributes<unknown>>;
|
package/dist/components/radio-group/components/radio-group-radio/radio-group-radio.component.js
CHANGED
|
@@ -17,13 +17,13 @@ import React, { forwardRef, useContext, useRef } from 'react';
|
|
|
17
17
|
import { VisuallyHidden, useFocusRing, useRadio } from 'react-aria';
|
|
18
18
|
import { RadioGroupContext } from '../../radio-group.component.js';
|
|
19
19
|
import { styles as radioStyles } from './radio-group-radio.styles.js';
|
|
20
|
-
function BaseRadioGroupRadio({ className , hint ,
|
|
20
|
+
function BaseRadioGroupRadio({ className , hint , label , ...props }, ref) {
|
|
21
21
|
const state = useContext(RadioGroupContext);
|
|
22
22
|
const { size , orientation } = state;
|
|
23
23
|
const localRef = useRef(null);
|
|
24
24
|
const { inputProps , isSelected , isDisabled } = useRadio({
|
|
25
25
|
...props,
|
|
26
|
-
children
|
|
26
|
+
children: label
|
|
27
27
|
}, state, localRef);
|
|
28
28
|
const { isFocusVisible , focusProps } = useFocusRing();
|
|
29
29
|
const styles = radioStyles({
|
|
@@ -46,7 +46,7 @@ function BaseRadioGroupRadio({ className , hint , children , ...props }, ref) {
|
|
|
46
46
|
className: styles.textWrapper()
|
|
47
47
|
}, React.createElement("span", {
|
|
48
48
|
className: styles.labelText()
|
|
49
|
-
},
|
|
49
|
+
}, label), hint && React.createElement("span", {
|
|
50
50
|
className: styles.hintText()
|
|
51
51
|
}, hint)));
|
|
52
52
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type RadioGroupContextState, type RadioGroupProps } from './radio-group.types.js';
|
|
3
3
|
export declare const RadioGroupContext: React.Context<RadioGroupContextState>;
|
|
4
|
-
export declare function RadioGroup({ className,
|
|
4
|
+
export declare function RadioGroup({ className, radios, label, orientation, showAmount, size, errorMessage, hintMessage, ...props }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -13,12 +13,12 @@ function _extends() {
|
|
|
13
13
|
};
|
|
14
14
|
return _extends.apply(this, arguments);
|
|
15
15
|
}
|
|
16
|
-
import React, {
|
|
16
|
+
import React, { createContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
17
17
|
import { useFocusRing, useRadioGroup } from 'react-aria';
|
|
18
18
|
import { useRadioGroupState } from 'react-stately';
|
|
19
19
|
import { Button } from '../button/index.js';
|
|
20
20
|
import { ExpandMoreIcon } from '../icon/index.js';
|
|
21
|
-
import { ErrorMessage, Hint, Label } from '../index.js';
|
|
21
|
+
import { ErrorMessage, Hint, Label, RadioGroupRadio } from '../index.js';
|
|
22
22
|
import { styles as radioGroupStyles } from './radio-group.styles.js';
|
|
23
23
|
export const RadioGroupContext = createContext({
|
|
24
24
|
name: '',
|
|
@@ -33,7 +33,7 @@ export const RadioGroupContext = createContext({
|
|
|
33
33
|
orientation: 'vertical',
|
|
34
34
|
size: 'medium'
|
|
35
35
|
});
|
|
36
|
-
export function RadioGroup({ className ,
|
|
36
|
+
export function RadioGroup({ className , radios , label , orientation ='vertical' , showAmount =0 , size ='medium' , errorMessage , hintMessage , ...props }) {
|
|
37
37
|
const state = useRadioGroupState({
|
|
38
38
|
...props,
|
|
39
39
|
label,
|
|
@@ -47,21 +47,19 @@ export function RadioGroup({ className , children , label , orientation ='vertic
|
|
|
47
47
|
const { isFocusVisible , focusProps } = useFocusRing();
|
|
48
48
|
const [hiddenOptions, setHiddenOptions] = useState(showAmount > 0);
|
|
49
49
|
const firstNewRadioRef = useRef(null);
|
|
50
|
-
const revealAmount =
|
|
50
|
+
const revealAmount = radios && radios.length - showAmount;
|
|
51
51
|
const styles = radioGroupStyles({
|
|
52
52
|
orientation,
|
|
53
53
|
isFocusVisible
|
|
54
54
|
});
|
|
55
55
|
const childrenToRender = useMemo(()=>{
|
|
56
|
-
const newChildren =
|
|
57
|
-
return cloneElement(child, {
|
|
56
|
+
const newChildren = radios.map((radio, index)=>React.createElement(RadioGroupRadio, _extends({
|
|
58
57
|
key: index,
|
|
59
58
|
ref: index === showAmount ? firstNewRadioRef : null
|
|
60
|
-
});
|
|
61
|
-
});
|
|
59
|
+
}, radio)));
|
|
62
60
|
return hiddenOptions ? newChildren.slice(0, showAmount) : newChildren;
|
|
63
61
|
}, [
|
|
64
|
-
|
|
62
|
+
radios,
|
|
65
63
|
hiddenOptions,
|
|
66
64
|
showAmount
|
|
67
65
|
]);
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
1
|
import { type AriaRadioGroupProps } from 'react-aria';
|
|
3
2
|
import { type RadioGroupState } from 'react-stately';
|
|
4
3
|
import { HintProps } from '../index.js';
|
|
4
|
+
import { RadioGroupRadioProps } from './components/radio-group-radio/radio-group-radio.types.js';
|
|
5
5
|
export type RadioGroupProps = {
|
|
6
|
-
/**
|
|
7
|
-
* The `Radio` components to render
|
|
8
|
-
*/
|
|
9
|
-
children: ReactNode[];
|
|
10
6
|
/**
|
|
11
7
|
* String to override base style
|
|
12
8
|
*/
|
|
@@ -19,6 +15,10 @@ export type RadioGroupProps = {
|
|
|
19
15
|
* hint message
|
|
20
16
|
*/
|
|
21
17
|
hintMessage?: HintProps['children'];
|
|
18
|
+
/**
|
|
19
|
+
* The `Radio` components to render
|
|
20
|
+
*/
|
|
21
|
+
radios: RadioGroupRadioProps[];
|
|
22
22
|
/**
|
|
23
23
|
* Amount of Radios to display, remainder will be hidden behind reveal button
|
|
24
24
|
*/
|