@westpac/ui 0.58.0 → 0.59.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/compacta/compacta.component.d.ts +1 -1
- package/dist/components/compacta/compacta.component.js +21 -1
- package/dist/components/compacta/compacta.types.d.ts +12 -0
- package/package.json +3 -3
- package/src/components/compacta/compacta.component.tsx +21 -0
- package/src/components/compacta/compacta.types.ts +10 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type CompactaProps } from './compacta.types.js';
|
|
2
|
-
export declare function Compacta({ className, children, titleTag: Tag, addText, ...props }: CompactaProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function Compacta({ className, children, titleTag: Tag, addText, initialCompactas, ...props }: CompactaProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -7,7 +7,7 @@ import { AddCircleIcon, ExpandLessIcon, ExpandMoreIcon, RemoveCircleIcon } from
|
|
|
7
7
|
import { VisuallyHidden } from '../index.js';
|
|
8
8
|
import { styles as compactaStyles } from './compacta.styles.js';
|
|
9
9
|
const loadAnimations = ()=>import('./compacta.utils.js').then((res)=>res.default);
|
|
10
|
-
export function Compacta({ className, children, titleTag: Tag = 'h3', addText = 'Add another', ...props }) {
|
|
10
|
+
export function Compacta({ className, children, titleTag: Tag = 'h3', addText = 'Add another', initialCompactas, ...props }) {
|
|
11
11
|
const [initial, setInitial] = useState(true);
|
|
12
12
|
const id = useId();
|
|
13
13
|
const [items, setItems] = useState([
|
|
@@ -129,6 +129,26 @@ export function Compacta({ className, children, titleTag: Tag = 'h3', addText =
|
|
|
129
129
|
items.length,
|
|
130
130
|
action
|
|
131
131
|
]);
|
|
132
|
+
useEffect(()=>{
|
|
133
|
+
if (initialCompactas) {
|
|
134
|
+
const newItems = initialCompactas.map((item, index)=>{
|
|
135
|
+
var _item_id, _ref, _ref1, _ref2;
|
|
136
|
+
var _item_title, _item_title1, _item_title2;
|
|
137
|
+
const itemId = (_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : `${id}-${generateID()}`;
|
|
138
|
+
return {
|
|
139
|
+
id: itemId,
|
|
140
|
+
open: index === initialCompactas.length - 1 ? true : false,
|
|
141
|
+
delay: false,
|
|
142
|
+
title: {
|
|
143
|
+
primary: (_ref = (_item_title = item.title) === null || _item_title === void 0 ? void 0 : _item_title.primary) !== null && _ref !== void 0 ? _ref : '',
|
|
144
|
+
secondary: (_ref1 = (_item_title1 = item.title) === null || _item_title1 === void 0 ? void 0 : _item_title1.secondary) !== null && _ref1 !== void 0 ? _ref1 : '',
|
|
145
|
+
tertiary: (_ref2 = (_item_title2 = item.title) === null || _item_title2 === void 0 ? void 0 : _item_title2.tertiary) !== null && _ref2 !== void 0 ? _ref2 : ''
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
setItems(newItems);
|
|
150
|
+
}
|
|
151
|
+
}, []);
|
|
132
152
|
const styles = compactaStyles({});
|
|
133
153
|
return React.createElement("div", {
|
|
134
154
|
className: styles.base({
|
|
@@ -8,6 +8,18 @@ export type CompactaProps = {
|
|
|
8
8
|
* Component to repeat
|
|
9
9
|
*/
|
|
10
10
|
children: (...props: ContentProps[]) => ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* The initial compactas to render. Each compacta needs a unique id if you want to pre-fill values.
|
|
13
|
+
* Each object contained within the array represents a compacta.
|
|
14
|
+
*/
|
|
15
|
+
initialCompactas?: {
|
|
16
|
+
id?: string;
|
|
17
|
+
title?: {
|
|
18
|
+
primary?: string;
|
|
19
|
+
secondary?: string;
|
|
20
|
+
tertiary?: string;
|
|
21
|
+
};
|
|
22
|
+
}[];
|
|
11
23
|
/**
|
|
12
24
|
* Tag for primary title
|
|
13
25
|
* @default h3
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@westpac/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -260,8 +260,8 @@
|
|
|
260
260
|
"vite": "^7.0.8",
|
|
261
261
|
"vitest": "^3.2.4",
|
|
262
262
|
"@westpac/eslint-config": "~1.0.1",
|
|
263
|
-
"@westpac/
|
|
264
|
-
"@westpac/
|
|
263
|
+
"@westpac/test-config": "~0.0.0",
|
|
264
|
+
"@westpac/ts-config": "~0.0.0"
|
|
265
265
|
},
|
|
266
266
|
"dependencies": {
|
|
267
267
|
"@duetds/date-picker": "~1.4.0",
|
|
@@ -24,6 +24,7 @@ export function Compacta({
|
|
|
24
24
|
children,
|
|
25
25
|
titleTag: Tag = 'h3',
|
|
26
26
|
addText = 'Add another',
|
|
27
|
+
initialCompactas,
|
|
27
28
|
...props
|
|
28
29
|
}: CompactaProps) {
|
|
29
30
|
const [initial, setInitial] = useState(true);
|
|
@@ -118,6 +119,26 @@ export function Compacta({
|
|
|
118
119
|
}
|
|
119
120
|
}, [items.length, action]);
|
|
120
121
|
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (initialCompactas) {
|
|
124
|
+
const newItems = initialCompactas.map((item, index) => {
|
|
125
|
+
const itemId = item.id ?? `${id}-${generateID()}`;
|
|
126
|
+
return {
|
|
127
|
+
id: itemId,
|
|
128
|
+
open: index === initialCompactas.length - 1 ? true : false,
|
|
129
|
+
delay: false,
|
|
130
|
+
title: {
|
|
131
|
+
primary: item.title?.primary ?? '',
|
|
132
|
+
secondary: item.title?.secondary ?? '',
|
|
133
|
+
tertiary: item.title?.tertiary ?? '',
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
setItems(newItems);
|
|
138
|
+
}
|
|
139
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
121
142
|
const styles = compactaStyles({});
|
|
122
143
|
|
|
123
144
|
return (
|
|
@@ -9,6 +9,16 @@ export type CompactaProps = {
|
|
|
9
9
|
* Component to repeat
|
|
10
10
|
*/
|
|
11
11
|
children: (...props: ContentProps[]) => ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* The initial compactas to render. Each compacta needs a unique id if you want to pre-fill values.
|
|
14
|
+
* Each object contained within the array represents a compacta.
|
|
15
|
+
*/
|
|
16
|
+
initialCompactas?: {
|
|
17
|
+
// Compacta id
|
|
18
|
+
id?: string;
|
|
19
|
+
// Titles to pre-fill, won't be done automatically
|
|
20
|
+
title?: { primary?: string; secondary?: string; tertiary?: string };
|
|
21
|
+
}[];
|
|
12
22
|
/**
|
|
13
23
|
* Tag for primary title
|
|
14
24
|
* @default h3
|