@westpac/ui 0.8.0 → 0.10.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 +13 -0
- package/assets/icons/filled/exit-filled.svg +3 -3
- package/assets/icons/outlined/exit-outlined.svg +3 -3
- package/dist/component-type.json +1 -1
- package/dist/components/accordion/accordion.styles.js +1 -1
- package/dist/components/accordion/components/accordion-item/accordion-item.styles.d.ts +2 -0
- package/dist/components/accordion/components/accordion-item/accordion-item.styles.js +2 -1
- package/dist/components/alert/alert.styles.js +4 -4
- package/dist/components/badge/badge.styles.js +1 -1
- package/dist/components/breadcrumb/components/breadcrumb-item/breadcrumb-item.component.js +1 -1
- package/dist/components/button/button.styles.js +4 -4
- package/dist/components/button-dropdown/components/panel/panel.styles.js +1 -1
- package/dist/components/button-group/components/button/button.styles.js +1 -1
- package/dist/components/checkbox-group/components/checkbox/checkbox.styles.js +1 -1
- package/dist/components/compacta/compacta.styles.js +4 -4
- package/dist/components/flexi-cell/flexi-cell.styles.js +1 -1
- package/dist/components/form-label/form-label.styles.d.ts +1 -1
- package/dist/components/form-label/form-label.styles.js +1 -1
- package/dist/components/icon/components/exit-icon.js +2 -2
- package/dist/components/input-field/components/add-ons/components/icon-add-on/icon-add-on.styles.js +6 -6
- package/dist/components/input-field/components/add-ons/components/text-add-on/text-add-on.styles.js +5 -5
- package/dist/components/list/components/item/item.styles.js +4 -4
- package/dist/components/modal/components/dialog/dialog.styles.js +1 -1
- package/dist/components/pagination/components/pagination-item/pagination-item.styles.d.ts +1 -1
- package/dist/components/pagination/components/pagination-item/pagination-item.styles.js +3 -3
- package/dist/components/panel/panel.styles.js +1 -1
- package/dist/components/popover/components/panel/panel.component.d.ts +1 -1
- package/dist/components/popover/components/panel/panel.component.js +39 -5
- package/dist/components/popover/components/panel/panel.styles.js +5 -5
- package/dist/components/popover/components/panel/panel.types.d.ts +12 -2
- package/dist/components/popover/popover.component.d.ts +4 -0
- package/dist/components/popover/popover.component.js +12 -6
- package/dist/components/popover/popover.hooks.d.ts +3 -0
- package/dist/components/popover/popover.hooks.js +37 -0
- package/dist/components/popover/popover.types.d.ts +1 -1
- package/dist/components/progress-bar/progress-bar.styles.js +2 -2
- package/dist/components/repeater/repeater.styles.js +4 -4
- package/dist/components/switch/switch.styles.js +1 -1
- package/dist/components/table/components/row/row.styles.js +1 -1
- package/dist/components/tabs/components/tab/tab.styles.d.ts +1 -1
- package/dist/components/tabs/components/tab/tab.styles.js +4 -4
- package/dist/components/well/well.styles.d.ts +1 -1
- package/dist/components/well/well.styles.js +1 -1
- package/dist/css/westpac-ui.css +481 -328
- package/dist/css/westpac-ui.min.css +481 -328
- package/dist/tailwind/__mocks__/utils.constants.d.ts +71 -36
- package/dist/tailwind/__mocks__/utils.constants.js +71 -36
- package/dist/tailwind/constants/spacing.d.ts +2 -36
- package/dist/tailwind/constants/spacing.js +2 -1
- package/dist/tailwind/tailwind-plugin.js +3 -0
- package/dist/tailwind/types/index.d.ts +0 -1
- package/dist/tailwind/types/index.js +0 -1
- package/dist/tailwind/utils/create-spacing.d.ts +2 -3
- package/dist/tailwind/utils/create-spacing.js +7 -7
- package/package.json +3 -1
- package/src/components/accordion/accordion.styles.ts +1 -1
- package/src/components/accordion/components/accordion-item/accordion-item.styles.ts +1 -0
- package/src/components/alert/alert.styles.ts +4 -4
- package/src/components/badge/badge.styles.ts +1 -1
- package/src/components/breadcrumb/components/breadcrumb-item/breadcrumb-item.component.tsx +1 -1
- package/src/components/button/button.styles.ts +4 -4
- package/src/components/button-dropdown/components/panel/panel.styles.ts +1 -2
- package/src/components/button-group/components/button/button.styles.ts +1 -1
- package/src/components/checkbox-group/components/checkbox/checkbox.styles.ts +1 -1
- package/src/components/compacta/compacta.styles.ts +4 -4
- package/src/components/error-message/error-message.component.tsx +1 -7
- package/src/components/flexi-cell/flexi-cell.styles.ts +1 -1
- package/src/components/form-label/form-label.styles.ts +1 -1
- package/src/components/icon/components/exit-icon.tsx +2 -2
- package/src/components/icon/index.ts +1 -0
- package/src/components/input-field/components/add-ons/components/icon-add-on/icon-add-on.styles.ts +16 -16
- package/src/components/input-field/components/add-ons/components/text-add-on/text-add-on.styles.ts +5 -5
- package/src/components/list/components/item/item.styles.ts +4 -4
- package/src/components/modal/components/dialog/dialog.styles.ts +1 -1
- package/src/components/pagination/components/pagination-item/pagination-item.styles.ts +3 -3
- package/src/components/panel/panel.styles.ts +1 -1
- package/src/components/popover/components/panel/panel.component.tsx +36 -6
- package/src/components/popover/components/panel/panel.styles.ts +5 -5
- package/src/components/popover/components/panel/panel.types.ts +13 -2
- package/src/components/popover/popover.component.tsx +13 -2
- package/src/components/popover/popover.hooks.tsx +56 -0
- package/src/components/popover/popover.types.ts +1 -1
- package/src/components/progress-bar/progress-bar.styles.ts +2 -2
- package/src/components/repeater/repeater.styles.ts +4 -4
- package/src/components/switch/switch.styles.ts +1 -1
- package/src/components/table/components/row/row.styles.ts +1 -1
- package/src/components/tabs/components/tab/tab.styles.ts +4 -4
- package/src/components/well/well.styles.ts +1 -1
- package/src/tailwind/__mocks__/utils.constants.ts +71 -36
- package/src/tailwind/constants/spacing.ts +2 -1
- package/src/tailwind/tailwind-plugin.ts +3 -0
- package/src/tailwind/types/index.ts +0 -1
- package/src/tailwind/utils/create-spacing.ts +9 -13
- package/tsconfig.build.json +1 -1
- package/.storybook/global.css +0 -109
- package/.storybook/main.ts +0 -33
- package/.storybook/manager.ts +0 -6
- package/.storybook/preview.tsx +0 -91
- package/.storybook/theme.ts +0 -9
- package/dist/components/accordion/accordion.stories.d.ts +0 -24
- package/dist/components/alert/alert.stories.d.ts +0 -29
- package/dist/components/autocomplete/autocomplete.stories.d.ts +0 -33
- package/dist/components/badge/badge.stories.d.ts +0 -25
- package/dist/components/breadcrumb/breadcrumb.stories.d.ts +0 -9
- package/dist/components/breadcrumb/components/breadcrumb-item/breadcrumb-item.stories.d.ts +0 -13
- package/dist/components/button/button.stories.d.ts +0 -37
- package/dist/components/button-dropdown/button-dropdown.stories.d.ts +0 -42
- package/dist/components/button-group/button-group.stories.d.ts +0 -33
- package/dist/components/checkbox-group/checkbox-group.stories.d.ts +0 -49
- package/dist/components/checkbox-group/components/checkbox/checkbox.stories.d.ts +0 -17
- package/dist/components/circle/circle.stories.d.ts +0 -9
- package/dist/components/collapsible/collapsible.stories.d.ts +0 -17
- package/dist/components/compacta/compacta.stories.d.ts +0 -8
- package/dist/components/date-picker/date-picker.stories.d.ts +0 -33
- package/dist/components/field/field.stories.d.ts +0 -16
- package/dist/components/flexi-cell/flexi-cell.stories.d.ts +0 -26
- package/dist/components/form/form.stories.d.ts +0 -21
- package/dist/components/grid/grid.stories.d.ts +0 -9
- package/dist/components/icon/icon.stories.d.ts +0 -21
- package/dist/components/input/input.stories.d.ts +0 -25
- package/dist/components/input-field/input-field.scenarios.stories.d.ts +0 -26
- package/dist/components/input-field/input-field.sizes.stories.d.ts +0 -9
- package/dist/components/input-field/input-field.state.stories.d.ts +0 -17
- package/dist/components/input-field/input-field.stories.d.ts +0 -25
- package/dist/components/input-field/input-field.type.stories.d.ts +0 -37
- package/dist/components/link/link.stories.d.ts +0 -22
- package/dist/components/list/list.stories.d.ts +0 -25
- package/dist/components/modal/modal.stories.d.ts +0 -21
- package/dist/components/pagination/pagination.stories.d.ts +0 -32
- package/dist/components/panel/panel.stories.d.ts +0 -21
- package/dist/components/pictogram/pictogram.stories.d.ts +0 -10
- package/dist/components/popover/popover.stories.d.ts +0 -25
- package/dist/components/progress-bar/progress-bar.stories.d.ts +0 -21
- package/dist/components/progress-rope/progress-rope.stories.d.ts +0 -13
- package/dist/components/radio-group/components/radio/radio.stories.d.ts +0 -17
- package/dist/components/radio-group/radio-group.stories.d.ts +0 -49
- package/dist/components/repeater/repeater.stories.d.ts +0 -13
- package/dist/components/select/select.stories.d.ts +0 -21
- package/dist/components/selector/selector.stories.d.ts +0 -56
- package/dist/components/skip-link/skip-link.stories.d.ts +0 -8
- package/dist/components/switch/switch.stories.d.ts +0 -29
- package/dist/components/symbol/symbol.stories.d.ts +0 -12
- package/dist/components/table/table.stories.d.ts +0 -25
- package/dist/components/tabs/tabs.stories.d.ts +0 -21
- package/dist/components/textarea/textarea.stories.d.ts +0 -25
- package/dist/components/visually-hidden/visually-hidden.stories.d.ts +0 -12
- package/dist/components/well/well.stories.d.ts +0 -25
- package/dist/stories/foundation/breakpoints.stories.d.ts +0 -8
- package/dist/stories/foundation/colours.stories.d.ts +0 -16
- package/dist/stories/foundation/spacing.stories.d.ts +0 -15
- package/dist/stories/foundation/theme.stories.d.ts +0 -7
- package/dist/stories/foundation/typography.stories.d.ts +0 -15
- package/dist/tailwind/types/theme.types.d.ts +0 -1
- package/dist/tailwind/types/theme.types.js +0 -1
- package/scaffold/component/scaffold.component.hbs +0 -12
- package/scaffold/component/scaffold.index.hbs +0 -2
- package/scaffold/component/scaffold.spec.hbs +0 -16
- package/scaffold/component/scaffold.stories.hbs +0 -23
- package/scaffold/component/scaffold.styles.hbs +0 -9
- package/scaffold/component/scaffold.types.hbs +0 -12
- package/src/tailwind/types/theme.types.ts +0 -37
|
@@ -42,19 +42,19 @@ export const styles = tv(
|
|
|
42
42
|
},
|
|
43
43
|
type: {
|
|
44
44
|
bullet: {
|
|
45
|
-
bullet: 'left-[0.25rem] top-
|
|
45
|
+
bullet: 'left-[0.25rem] top-1 h-[0.5rem] w-[0.5rem] rounded-full',
|
|
46
46
|
},
|
|
47
47
|
link: {
|
|
48
48
|
bullet:
|
|
49
|
-
'left-[0.125rem] top-
|
|
49
|
+
'left-[0.125rem] top-1 h-[0.5rem] w-[0.5rem] rotate-45 border-b-0 border-l-0 border-r-[0.125rem] border-t-[0.125rem] bg-[transparent]',
|
|
50
50
|
},
|
|
51
51
|
tick: {
|
|
52
52
|
bullet:
|
|
53
|
-
' left-[0.125rem] top-[0.3125rem] h-
|
|
53
|
+
' left-[0.125rem] top-[0.3125rem] h-1 w-2 rotate-[-44deg] border-b-[0.125rem] border-l-[0.125rem] border-r-0 border-t-0 bg-[transparent]',
|
|
54
54
|
},
|
|
55
55
|
cross: {
|
|
56
56
|
bullet:
|
|
57
|
-
'left-
|
|
57
|
+
'left-1 top-[0.25rem] h-2 w-0 -rotate-45 border-y-0 border-l-[0.125rem] border-r-0 bg-[transparent] after:absolute after:left-[-0.125rem] after:block after:h-2 after:w-0 after:rotate-90 after:border-y-0 after:border-l-[0.125rem] after:border-r-0',
|
|
58
58
|
},
|
|
59
59
|
unstyled: {
|
|
60
60
|
base: 'pl-0',
|
|
@@ -3,7 +3,7 @@ import { tv } from 'tailwind-variants';
|
|
|
3
3
|
export const styles = tv(
|
|
4
4
|
{
|
|
5
5
|
slots: {
|
|
6
|
-
base: 'relative mx-auto max-w-full overflow-hidden rounded
|
|
6
|
+
base: 'relative mx-auto max-w-full overflow-hidden rounded bg-white outline-none',
|
|
7
7
|
title: 'border-b border-b-heading pb-2 pl-4 pr-5 pt-3 text-lg font-medium',
|
|
8
8
|
close: 'absolute right-1 top-1 block p-1',
|
|
9
9
|
},
|
|
@@ -2,14 +2,14 @@ import { tv } from 'tailwind-variants';
|
|
|
2
2
|
|
|
3
3
|
export const styles = tv(
|
|
4
4
|
{
|
|
5
|
-
base: 'typography-body-10 relative block border border-border px-2 py-
|
|
5
|
+
base: 'typography-body-10 relative block border border-border px-2 py-1.5 text-center text-text transition-colors',
|
|
6
6
|
variants: {
|
|
7
7
|
firstItem: {
|
|
8
|
-
true: 'rounded-l
|
|
8
|
+
true: 'rounded-l',
|
|
9
9
|
false: 'ml-[-1px]',
|
|
10
10
|
},
|
|
11
11
|
lastItem: {
|
|
12
|
-
true: 'rounded-r
|
|
12
|
+
true: 'rounded-r',
|
|
13
13
|
false: '',
|
|
14
14
|
},
|
|
15
15
|
active: {
|
|
@@ -3,7 +3,7 @@ import { tv } from 'tailwind-variants';
|
|
|
3
3
|
export const styles = tv(
|
|
4
4
|
{
|
|
5
5
|
slots: {
|
|
6
|
-
base: 'group/panel mb-4 overflow-hidden rounded
|
|
6
|
+
base: 'group/panel mb-4 overflow-hidden rounded border border-hero',
|
|
7
7
|
header: 'px-2 py-[0.625rem] sm:px-4',
|
|
8
8
|
},
|
|
9
9
|
variants: {
|
|
@@ -1,18 +1,48 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
2
2
|
import { FocusScope } from 'react-aria';
|
|
3
3
|
|
|
4
4
|
import { Button } from '../../../button/index.js';
|
|
5
5
|
import { CloseIcon } from '../../../icon/index.js';
|
|
6
|
+
import { usePopoverPosition } from '../../popover.hooks.js';
|
|
6
7
|
|
|
7
8
|
import { styles as panelStyles } from './panel.styles.js';
|
|
8
|
-
import { type PanelProps } from './panel.types.js';
|
|
9
|
+
import { type PanelProps, Position } from './panel.types.js';
|
|
9
10
|
|
|
10
|
-
export function Panel({ state, heading, headingTag: Tag = 'h1', content, placement
|
|
11
|
-
const
|
|
11
|
+
export function Panel({ state, heading, headingTag: Tag = 'h1', content, placement, id, triggerRef }: PanelProps) {
|
|
12
|
+
const popoverRef = useRef<HTMLDivElement>(null);
|
|
13
|
+
const arrowRef = useRef<HTMLDivElement>(null);
|
|
14
|
+
const remSize = parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
|
|
15
|
+
|
|
16
|
+
const [position, setPosition] = useState<Position>({
|
|
17
|
+
placement: 'top',
|
|
18
|
+
offset: 'left',
|
|
19
|
+
panelPosition: triggerRef.current ? triggerRef.current.offsetWidth / 2 / remSize : 0,
|
|
20
|
+
arrowPosition: popoverRef.current ? popoverRef.current.getBoundingClientRect().width / 2 / remSize : 0,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
setPosition(usePopoverPosition(triggerRef, popoverRef, arrowRef, placement));
|
|
25
|
+
}, [state.isOpen]);
|
|
26
|
+
|
|
27
|
+
const getPopoverClass = useCallback(() => {
|
|
28
|
+
return {
|
|
29
|
+
[position.offset as string]:
|
|
30
|
+
position.offset === 'left' ? `${position.panelPosition}rem` : `-${position.panelPosition}rem`,
|
|
31
|
+
transform: position.offset === 'left' ? 'translateX(-50%)' : 'none',
|
|
32
|
+
};
|
|
33
|
+
}, [position]);
|
|
34
|
+
|
|
35
|
+
const getArrowClass = useCallback(() => {
|
|
36
|
+
return {
|
|
37
|
+
[!position.offset || position.offset === 'left' ? 'left' : 'right']: `${position.arrowPosition}rem`,
|
|
38
|
+
};
|
|
39
|
+
}, [position]);
|
|
40
|
+
|
|
41
|
+
const styles = panelStyles({ placement: position.placement });
|
|
12
42
|
|
|
13
43
|
return (
|
|
14
44
|
<FocusScope restoreFocus>
|
|
15
|
-
<div className={styles.popover()} id={id}>
|
|
45
|
+
<div className={styles.popover()} style={getPopoverClass()} id={id} ref={popoverRef}>
|
|
16
46
|
<div className={styles.content()}>
|
|
17
47
|
<Tag className={styles.heading()}>{heading}</Tag>
|
|
18
48
|
<div className={styles.body()}>{content}</div>
|
|
@@ -24,7 +54,7 @@ export function Panel({ state, heading, headingTag: Tag = 'h1', content, placeme
|
|
|
24
54
|
aria-label="Close popover"
|
|
25
55
|
/>
|
|
26
56
|
</div>
|
|
27
|
-
<div aria-hidden className={styles.arrow()} />
|
|
57
|
+
<div aria-hidden className={styles.arrow()} style={getArrowClass()} ref={arrowRef} />
|
|
28
58
|
</div>
|
|
29
59
|
</FocusScope>
|
|
30
60
|
);
|
|
@@ -4,7 +4,7 @@ export const styles = tv(
|
|
|
4
4
|
{
|
|
5
5
|
slots: {
|
|
6
6
|
base: '',
|
|
7
|
-
popover: 'absolute z-[999] rounded
|
|
7
|
+
popover: 'absolute z-[999] rounded border border-muted bg-white shadow-[0_5px_10px_rgba(0,0,0,0.2)]',
|
|
8
8
|
arrow:
|
|
9
9
|
'absolute h-0 w-0 border-x-[8px] border-t-[12px] border-x-[transparent] border-t-muted after:absolute after:h-0 after:w-0 after:border-x-[7px] after:border-t-[11px] after:border-x-[transparent] after:border-t-white',
|
|
10
10
|
closeBtn: 'absolute right-1 top-1 m-1 p-0 hover:opacity-80',
|
|
@@ -15,12 +15,12 @@ export const styles = tv(
|
|
|
15
15
|
variants: {
|
|
16
16
|
placement: {
|
|
17
17
|
top: {
|
|
18
|
-
popover: 'bottom-full
|
|
19
|
-
arrow: '
|
|
18
|
+
popover: 'bottom-full mb-2.5',
|
|
19
|
+
arrow: 'top-full after:top-[-12px] after:translate-x-[-7px]',
|
|
20
20
|
},
|
|
21
21
|
bottom: {
|
|
22
|
-
popover: '
|
|
23
|
-
arrow: 'bottom-full
|
|
22
|
+
popover: 'top-full mt-2.5',
|
|
23
|
+
arrow: 'bottom-full rotate-180 after:bottom-[1px] after:translate-x-[-7px]',
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
26
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTMLAttributes } from 'react';
|
|
1
|
+
import { HTMLAttributes, RefObject } from 'react';
|
|
2
2
|
import { OverlayTriggerState } from 'react-stately';
|
|
3
3
|
|
|
4
4
|
export type PanelProps = {
|
|
@@ -15,11 +15,22 @@ export type PanelProps = {
|
|
|
15
15
|
*/
|
|
16
16
|
headingTag?: keyof Pick<JSX.IntrinsicElements, 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'>;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Placement of popover. If no placement provided it will default to top unless there is no space then will appear on bottom.
|
|
19
19
|
*/
|
|
20
20
|
placement?: 'top' | 'bottom';
|
|
21
21
|
/**
|
|
22
22
|
* Overlay trigger state
|
|
23
23
|
*/
|
|
24
24
|
state: OverlayTriggerState;
|
|
25
|
+
/**
|
|
26
|
+
* Ref for the trigger
|
|
27
|
+
*/
|
|
28
|
+
triggerRef: RefObject<HTMLDivElement>;
|
|
25
29
|
} & HTMLAttributes<Element>;
|
|
30
|
+
|
|
31
|
+
export type Position = {
|
|
32
|
+
arrowPosition?: number;
|
|
33
|
+
offset?: 'left' | 'right';
|
|
34
|
+
panelPosition?: number;
|
|
35
|
+
placement?: 'top' | 'bottom';
|
|
36
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { useCallback, useEffect, useId } from 'react';
|
|
3
|
+
import React, { useCallback, useEffect, useId, useLayoutEffect, useRef } from 'react';
|
|
4
4
|
import { useOverlayTriggerState } from 'react-stately';
|
|
5
5
|
|
|
6
6
|
import { Button } from '../button/index.js';
|
|
@@ -9,6 +9,11 @@ import { Panel } from './components/panel/panel.component.js';
|
|
|
9
9
|
import { styles as popoverStyles } from './popover.styles.js';
|
|
10
10
|
import { type PopoverProps } from './popover.types.js';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* TODO: Revisit this component when react-aria has updated usePopover, see: https://github.com/adobe/react-spectrum/discussions/5341
|
|
14
|
+
* This version does not currently use react-aria as it blocked so functionality that was needed to match GEL 3.0
|
|
15
|
+
*/
|
|
16
|
+
|
|
12
17
|
export function Popover({
|
|
13
18
|
children,
|
|
14
19
|
className,
|
|
@@ -21,9 +26,10 @@ export function Popover({
|
|
|
21
26
|
open = false,
|
|
22
27
|
icon,
|
|
23
28
|
}: PopoverProps) {
|
|
24
|
-
const state = useOverlayTriggerState({
|
|
29
|
+
const state = useOverlayTriggerState({});
|
|
25
30
|
const panelId = useId();
|
|
26
31
|
const styles = popoverStyles({});
|
|
32
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
27
33
|
|
|
28
34
|
const handleClick = useCallback(() => {
|
|
29
35
|
onClick();
|
|
@@ -44,6 +50,9 @@ export function Popover({
|
|
|
44
50
|
};
|
|
45
51
|
}, [state.isOpen]);
|
|
46
52
|
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
if (open) state.setOpen(true);
|
|
55
|
+
}, [open]);
|
|
47
56
|
return (
|
|
48
57
|
<div className={styles.base({ className })}>
|
|
49
58
|
<Button
|
|
@@ -52,6 +61,7 @@ export function Popover({
|
|
|
52
61
|
aria-expanded={state.isOpen}
|
|
53
62
|
aria-controls={panelId}
|
|
54
63
|
onClick={handleClick}
|
|
64
|
+
ref={ref}
|
|
55
65
|
>
|
|
56
66
|
{children}
|
|
57
67
|
</Button>
|
|
@@ -63,6 +73,7 @@ export function Popover({
|
|
|
63
73
|
content={content}
|
|
64
74
|
state={state}
|
|
65
75
|
id={panelId}
|
|
76
|
+
triggerRef={ref}
|
|
66
77
|
/>
|
|
67
78
|
)}
|
|
68
79
|
</div>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Position } from './components/panel/panel.types.js';
|
|
4
|
+
|
|
5
|
+
export const usePopoverPosition = (
|
|
6
|
+
triggerRef: RefObject<HTMLDivElement>,
|
|
7
|
+
popoverRef: RefObject<HTMLDivElement>,
|
|
8
|
+
arrowRef: RefObject<HTMLDivElement>,
|
|
9
|
+
placement?: 'top' | 'bottom',
|
|
10
|
+
): Position => {
|
|
11
|
+
// bail early without refs
|
|
12
|
+
if (!triggerRef.current || !popoverRef.current || !arrowRef.current) {
|
|
13
|
+
throw new Error('You must pass valid refs.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const trigger = triggerRef.current.getBoundingClientRect();
|
|
17
|
+
const popover = popoverRef.current.getBoundingClientRect();
|
|
18
|
+
const arrow = arrowRef.current.getBoundingClientRect();
|
|
19
|
+
const remSize = parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
|
|
20
|
+
|
|
21
|
+
const position: Position = {
|
|
22
|
+
placement: placement ? placement : 'top',
|
|
23
|
+
offset: popover.right >= window.innerWidth ? 'right' : 'left',
|
|
24
|
+
panelPosition: trigger.width / 2 / remSize,
|
|
25
|
+
arrowPosition: (popover.width / 2 - arrow.width / 2) / remSize,
|
|
26
|
+
};
|
|
27
|
+
if (typeof window === 'undefined') {
|
|
28
|
+
return position;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const offLeft = popover.left <= 0;
|
|
32
|
+
const offRight = popover.right + remSize >= window.innerWidth;
|
|
33
|
+
|
|
34
|
+
if (offLeft) {
|
|
35
|
+
position.panelPosition = (popover.width - popover.right + trigger.width / 2 + remSize) / remSize;
|
|
36
|
+
position.arrowPosition = (trigger.right - trigger.width / 2 - arrow.width / 2 - remSize) / remSize;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (offRight) {
|
|
40
|
+
position.panelPosition = (window.innerWidth - trigger.right - remSize) / remSize;
|
|
41
|
+
position.arrowPosition =
|
|
42
|
+
(window.innerWidth - (trigger.left + trigger.width / 2) - (remSize + arrow.width / 2)) / remSize;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (popover.height > trigger.top) {
|
|
46
|
+
position.placement = placement ? placement : 'bottom';
|
|
47
|
+
return position;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (popover.bottom > window.innerHeight) {
|
|
51
|
+
position.placement = placement ? placement : 'top';
|
|
52
|
+
return position;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return position;
|
|
56
|
+
};
|
|
@@ -33,7 +33,7 @@ export type PopoverProps = {
|
|
|
33
33
|
*/
|
|
34
34
|
open?: boolean;
|
|
35
35
|
/**
|
|
36
|
-
* Placement of popover
|
|
36
|
+
* Placement of popover. If no placement provided it will default to top unless there is no space then will appear on bottom.
|
|
37
37
|
*/
|
|
38
38
|
placement?: 'top' | 'bottom';
|
|
39
39
|
} & HTMLAttributes<Element> &
|
|
@@ -5,12 +5,12 @@ export const styles = tv(
|
|
|
5
5
|
slots: {
|
|
6
6
|
base: 'box-border w-full overflow-hidden border border-border bg-white p-[0.0625rem]',
|
|
7
7
|
innerBar: 'box-border h-full bg-hero text-right leading-tight transition-[width] duration-[.6s]',
|
|
8
|
-
label: 'typography-body-10 mx-
|
|
8
|
+
label: 'typography-body-10 mx-2 my-0 block font-bold text-white',
|
|
9
9
|
},
|
|
10
10
|
variants: {
|
|
11
11
|
look: {
|
|
12
12
|
default: {
|
|
13
|
-
base: 'h-
|
|
13
|
+
base: 'h-4 rounded-[1.5rem]',
|
|
14
14
|
innerBar: ' rounded-[1.5rem]',
|
|
15
15
|
},
|
|
16
16
|
skinny: {
|
|
@@ -6,11 +6,11 @@ export const styles = tv(
|
|
|
6
6
|
base: '',
|
|
7
7
|
list: 'm-0 flex list-none flex-col pl-0',
|
|
8
8
|
item: 'relative',
|
|
9
|
-
itemIndex: 'mb-
|
|
9
|
+
itemIndex: 'mb-3 font-bold',
|
|
10
10
|
content: '',
|
|
11
11
|
removeBtn: 'absolute right-0 top-0 h-auto p-0 no-underline hover:underline',
|
|
12
12
|
footer: 'flex justify-between pt-[0.875rem]',
|
|
13
|
-
addBtn: '
|
|
13
|
+
addBtn: 'h-auto p-0 no-underline hover:underline',
|
|
14
14
|
},
|
|
15
15
|
variants: {
|
|
16
16
|
separator: {
|
|
@@ -19,8 +19,8 @@ export const styles = tv(
|
|
|
19
19
|
},
|
|
20
20
|
true: {
|
|
21
21
|
item: 'border-t-2 border-neutral pt-[0.625rem]',
|
|
22
|
-
content: '
|
|
23
|
-
removeBtn: 'relative
|
|
22
|
+
content: 'px-3 pb-7 pt-0',
|
|
23
|
+
removeBtn: 'relative mb-5 ml-3',
|
|
24
24
|
footer: 'border-t-2 border-neutral',
|
|
25
25
|
},
|
|
26
26
|
},
|
|
@@ -5,7 +5,7 @@ export const styles = tv(
|
|
|
5
5
|
slots: {
|
|
6
6
|
base: 'mb-1 inline-flex items-center hover:cursor-pointer',
|
|
7
7
|
switchDiv:
|
|
8
|
-
'relative box-content overflow-hidden border border-borderDark transition duration-[.3s] after:absolute after:left-0 after:top-0 after:block after:rounded-
|
|
8
|
+
'relative box-content overflow-hidden border border-borderDark transition duration-[.3s] after:absolute after:left-0 after:top-0 after:block after:rounded-full after:bg-white after:shadow-switch after:transition-all after:duration-[.3s]',
|
|
9
9
|
label: 'pr-1',
|
|
10
10
|
},
|
|
11
11
|
variants: {
|
|
@@ -4,7 +4,7 @@ export const styles = tv(
|
|
|
4
4
|
{
|
|
5
5
|
slots: { base: 'hover:bg-background' },
|
|
6
6
|
variants: {
|
|
7
|
-
striped: { true: { base: '
|
|
7
|
+
striped: { true: { base: 'even:bg-background hover:bg-[transparent]' } },
|
|
8
8
|
highlightedRow: { true: { base: 'border border-b-[3px] border-l-[6px] border-r-0 border-primary' } },
|
|
9
9
|
},
|
|
10
10
|
},
|
|
@@ -2,7 +2,7 @@ import { tv } from 'tailwind-variants';
|
|
|
2
2
|
|
|
3
3
|
export const styles = tv(
|
|
4
4
|
{
|
|
5
|
-
base: 'typography-body-9 flex cursor-pointer px-3 py-2 text-text transition-colors
|
|
5
|
+
base: 'typography-body-9 flex cursor-pointer px-3 py-2 text-text transition-colors',
|
|
6
6
|
variants: {
|
|
7
7
|
look: {
|
|
8
8
|
default: 'border border-border bg-white',
|
|
@@ -10,7 +10,7 @@ export const styles = tv(
|
|
|
10
10
|
},
|
|
11
11
|
selected: {
|
|
12
12
|
true: 'bg-white',
|
|
13
|
-
false: '',
|
|
13
|
+
false: 'hover:bg-background',
|
|
14
14
|
},
|
|
15
15
|
orientation: {
|
|
16
16
|
horizontal: '',
|
|
@@ -37,12 +37,12 @@ export const styles = tv(
|
|
|
37
37
|
{
|
|
38
38
|
orientation: 'horizontal',
|
|
39
39
|
look: 'default',
|
|
40
|
-
className: 'rounded-t
|
|
40
|
+
className: 'rounded-t',
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
orientation: 'vertical',
|
|
44
44
|
look: 'default',
|
|
45
|
-
className: 'rounded-l
|
|
45
|
+
className: 'rounded-l',
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
orientation: 'horizontal',
|
|
@@ -1,40 +1,75 @@
|
|
|
1
1
|
export const EXPECTED_SPACING = {
|
|
2
|
-
0: '
|
|
3
|
-
1: '0.375rem',
|
|
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
|
-
|
|
2
|
+
'0': '0rem',
|
|
3
|
+
'1': '0.375rem',
|
|
4
|
+
'2': '0.75rem',
|
|
5
|
+
'3': '1.125rem',
|
|
6
|
+
'4': '1.5rem',
|
|
7
|
+
'5': '1.875rem',
|
|
8
|
+
'6': '2.25rem',
|
|
9
|
+
'7': '2.625rem',
|
|
10
|
+
'8': '3rem',
|
|
11
|
+
'9': '3.375rem',
|
|
12
|
+
'10': '3.75rem',
|
|
13
|
+
'11': '4.125rem',
|
|
14
|
+
'12': '4.5rem',
|
|
15
|
+
'13': '4.875rem',
|
|
16
|
+
'14': '5.25rem',
|
|
17
|
+
'15': '5.625rem',
|
|
18
|
+
'16': '6rem',
|
|
19
|
+
'17': '6.375rem',
|
|
20
|
+
'18': '6.75rem',
|
|
21
|
+
'19': '7.125rem',
|
|
22
|
+
'20': '7.5rem',
|
|
23
|
+
'21': '7.875rem',
|
|
24
|
+
'22': '8.25rem',
|
|
25
|
+
'23': '8.625rem',
|
|
26
|
+
'24': '9rem',
|
|
27
|
+
'25': '9.375rem',
|
|
28
|
+
'26': '9.75rem',
|
|
29
|
+
'27': '10.125rem',
|
|
30
|
+
'28': '10.5rem',
|
|
31
|
+
'29': '10.875rem',
|
|
32
|
+
'30': '11.25rem',
|
|
33
|
+
'31': '11.625rem',
|
|
34
|
+
'32': '12rem',
|
|
35
|
+
'33': '12.375rem',
|
|
36
|
+
'34': '12.75rem',
|
|
37
|
+
'35': '13.125rem',
|
|
38
|
+
'0.5': '0.1875rem',
|
|
39
|
+
'1.5': '0.5625rem',
|
|
40
|
+
'2.5': '0.9375rem',
|
|
41
|
+
'3.5': '1.3125rem',
|
|
42
|
+
'4.5': '1.6875rem',
|
|
43
|
+
'5.5': '2.0625rem',
|
|
44
|
+
'6.5': '2.4375rem',
|
|
45
|
+
'7.5': '2.8125rem',
|
|
46
|
+
'8.5': '3.1875rem',
|
|
47
|
+
'9.5': '3.5625rem',
|
|
48
|
+
'10.5': '3.9375rem',
|
|
49
|
+
'11.5': '4.3125rem',
|
|
50
|
+
'12.5': '4.6875rem',
|
|
51
|
+
'13.5': '5.0625rem',
|
|
52
|
+
'14.5': '5.4375rem',
|
|
53
|
+
'15.5': '5.8125rem',
|
|
54
|
+
'16.5': '6.1875rem',
|
|
55
|
+
'17.5': '6.5625rem',
|
|
56
|
+
'18.5': '6.9375rem',
|
|
57
|
+
'19.5': '7.3125rem',
|
|
58
|
+
'20.5': '7.6875rem',
|
|
59
|
+
'21.5': '8.0625rem',
|
|
60
|
+
'22.5': '8.4375rem',
|
|
61
|
+
'23.5': '8.8125rem',
|
|
62
|
+
'24.5': '9.1875rem',
|
|
63
|
+
'25.5': '9.5625rem',
|
|
64
|
+
'26.5': '9.9375rem',
|
|
65
|
+
'27.5': '10.3125rem',
|
|
66
|
+
'28.5': '10.6875rem',
|
|
67
|
+
'29.5': '11.0625rem',
|
|
68
|
+
'30.5': '11.4375rem',
|
|
69
|
+
'31.5': '11.8125rem',
|
|
70
|
+
'32.5': '12.1875rem',
|
|
71
|
+
'33.5': '12.5625rem',
|
|
72
|
+
'34.5': '12.9375rem',
|
|
38
73
|
};
|
|
39
74
|
|
|
40
75
|
export const EXPECTED_FONT_SIZES_VARS = {
|
|
@@ -3,5 +3,6 @@ import { createSpacing } from '../utils/create-spacing.js';
|
|
|
3
3
|
export const SPACING_LENGTH = 35;
|
|
4
4
|
export const SPACING_UNIT = 6;
|
|
5
5
|
export const SPACING_SCALE = 16;
|
|
6
|
+
export const ADD_MINOR_SCALE = true;
|
|
6
7
|
|
|
7
|
-
export const SPACING = createSpacing(SPACING_UNIT, SPACING_SCALE);
|
|
8
|
+
export const SPACING = createSpacing(SPACING_UNIT, SPACING_SCALE, ADD_MINOR_SCALE);
|
|
@@ -51,6 +51,9 @@ export const WestpacUIKitBasePlugin = plugin(
|
|
|
51
51
|
// See https://stackoverflow.com/questions/19982651/why-does-bootstrap-set-the-line-height-property-to-1-428571429 for below line height reasoning
|
|
52
52
|
loose: '1.428571429',
|
|
53
53
|
},
|
|
54
|
+
borderRadius: {
|
|
55
|
+
DEFAULT: '0.1875rem',
|
|
56
|
+
},
|
|
54
57
|
borderWidth: {
|
|
55
58
|
5: '0.3125rem',
|
|
56
59
|
},
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return spacing;
|
|
11
|
-
},
|
|
12
|
-
{ 0: '0' } as SpacingRecord,
|
|
13
|
-
);
|
|
1
|
+
type SpacingRecord = Record<number, string>;
|
|
2
|
+
export const createSpacing = (spacingUnit: number, spacingScale: number, addMinorScale: boolean) => {
|
|
3
|
+
return Array.from({ length: 36 }).reduce<SpacingRecord>((spacing, _, i) => {
|
|
4
|
+
spacing[i] = `${(i * spacingUnit) / spacingScale}rem`;
|
|
5
|
+
if (addMinorScale && i < 35) {
|
|
6
|
+
spacing[i + 0.5] = `${((i + 0.5) * spacingUnit) / spacingScale}rem`;
|
|
7
|
+
}
|
|
8
|
+
return spacing;
|
|
9
|
+
}, {} as SpacingRecord);
|
|
14
10
|
};
|
package/tsconfig.build.json
CHANGED