@westpac/ui 0.18.0 → 0.19.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @westpac/ui
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b9ec8e3: bottom sheet fix
8
+
3
9
  ## 0.18.0
4
10
 
5
11
  ### Minor Changes
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  function _extends() {
2
3
  _extends = Object.assign || function(target) {
3
4
  for(var i = 1; i < arguments.length; i++){
@@ -13,20 +14,24 @@ function _extends() {
13
14
  return _extends.apply(this, arguments);
14
15
  }
15
16
  import { clsx } from 'clsx';
16
- import * as React from 'react';
17
+ import React, { useMemo, useRef } from 'react';
17
18
  import { DismissButton, Overlay, usePopover } from 'react-aria';
18
19
  export function AutocompletePopover(props) {
19
20
  var _props_triggerRef_current;
20
- const ref = React.useRef(null);
21
+ const ref = useRef(null);
21
22
  const { popoverRef =ref , state , children , className , isNonModal , portalContainer } = props;
22
23
  const { popoverProps , underlayProps } = usePopover({
23
24
  ...props,
24
25
  popoverRef
25
26
  }, state);
26
- const brandContainer = document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]');
27
+ const brandContainer = useMemo(()=>{
28
+ if (typeof window !== 'undefined') {
29
+ return document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]') || document.body;
30
+ }
31
+ }, []);
27
32
  const width = (_props_triggerRef_current = props.triggerRef.current) === null || _props_triggerRef_current === void 0 ? void 0 : _props_triggerRef_current.getBoundingClientRect().width;
28
33
  return React.createElement(Overlay, {
29
- portalContainer: portalContainer || brandContainer || document.body
34
+ portalContainer: portalContainer || brandContainer
30
35
  }, !isNonModal && React.createElement("div", _extends({}, underlayProps, {
31
36
  className: "fixed inset-0"
32
37
  })), React.createElement("div", _extends({}, popoverProps, {
@@ -13,7 +13,7 @@ function _extends() {
13
13
  return _extends.apply(this, arguments);
14
14
  }
15
15
  import { motion, useAnimation } from 'framer-motion';
16
- import React, { useCallback, useEffect, useRef, useState } from 'react';
16
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
17
17
  import { Overlay, useModalOverlay } from 'react-aria';
18
18
  import { BREAKPOINTS } from '../../../../tailwind/constants/index.js';
19
19
  import { styles as bottomSheetModalStyles } from './bottom-sheet-modal.styles.js';
@@ -32,7 +32,11 @@ export function BottomSheetModal({ state , height , width , children , portalCon
32
32
  const { modalProps , underlayProps } = useModalOverlay(props, state, ref);
33
33
  const controls = useAnimation();
34
34
  const [isMobile, setIsMobile] = useState(checkIfItIsMobile(MEDIUM_BREAKPOINT_AS_NUMBER));
35
- const brandContainer = document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]');
35
+ const brandContainer = useMemo(()=>{
36
+ if (isBrowser) {
37
+ return document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]') || document.body;
38
+ }
39
+ }, []);
36
40
  useEffect(()=>{
37
41
  function handleResize() {
38
42
  setIsMobile(checkIfItIsMobile(MEDIUM_BREAKPOINT_AS_NUMBER));
@@ -65,7 +69,7 @@ export function BottomSheetModal({ state , height , width , children , portalCon
65
69
  return null;
66
70
  }
67
71
  return React.createElement(Overlay, {
68
- portalContainer: portalContainer || brandContainer || document.body
72
+ portalContainer: portalContainer || brandContainer
69
73
  }, React.createElement("div", _extends({
70
74
  className: styles.underlay()
71
75
  }, underlayProps), React.createElement(motion.div, {
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  function _extends() {
2
3
  _extends = Object.assign || function(target) {
3
4
  for(var i = 1; i < arguments.length; i++){
@@ -12,7 +13,7 @@ function _extends() {
12
13
  };
13
14
  return _extends.apply(this, arguments);
14
15
  }
15
- import React, { useRef } from 'react';
16
+ import React, { useMemo, useRef } from 'react';
16
17
  import { Overlay, useModalOverlay } from 'react-aria';
17
18
  import { styles as backdropStyles } from './modal-backdrop.styles.js';
18
19
  export function ModalBackdrop({ zIndex =100 , portalContainer , size , ...props }) {
@@ -24,12 +25,16 @@ export function ModalBackdrop({ zIndex =100 , portalContainer , size , ...props
24
25
  fluid: size === 'fluid'
25
26
  });
26
27
  const { modalProps , underlayProps } = useModalOverlay(props, state, ref);
28
+ const brandContainer = useMemo(()=>{
29
+ if (typeof window !== 'undefined') {
30
+ return document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]') || document.body;
31
+ }
32
+ }, []);
27
33
  if (!state.isOpen) {
28
34
  return null;
29
35
  }
30
- const brandContainer = document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]');
31
36
  return React.createElement(Overlay, {
32
- portalContainer: portalContainer || brandContainer || document.body
37
+ portalContainer: portalContainer || brandContainer
33
38
  }, React.createElement("div", _extends({
34
39
  style: {
35
40
  zIndex
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
1
+ import React, { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
2
2
  import { FocusScope } from 'react-aria';
3
3
  import { Button } from '../../../button/index.js';
4
4
  import { CloseIcon } from '../../../icon/index.js';
@@ -7,7 +7,12 @@ import { styles as panelStyles } from './panel.styles.js';
7
7
  export function Panel({ state , heading , headingTag: Tag = 'h1' , content , placement , id , triggerRef }) {
8
8
  const popoverRef = useRef(null);
9
9
  const arrowRef = useRef(null);
10
- const remSize = parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
10
+ const remSize = useMemo(()=>{
11
+ if (typeof window !== 'undefined') {
12
+ return parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
13
+ }
14
+ return 1;
15
+ }, []);
11
16
  const [position, setPosition] = useState({
12
17
  placement: 'top',
13
18
  offset: 'left',
@@ -5,7 +5,7 @@ export const usePopoverPosition = (triggerRef, popoverRef, arrowRef, placement)=
5
5
  const trigger = triggerRef.current.getBoundingClientRect();
6
6
  const popover = popoverRef.current.getBoundingClientRect();
7
7
  const arrow = arrowRef.current.getBoundingClientRect();
8
- const remSize = parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
8
+ const remSize = typeof window !== 'undefined' ? parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize) : 1;
9
9
  const position = {
10
10
  placement: placement ? placement : 'top',
11
11
  offset: popover.right >= window.innerWidth ? 'right' : 'left',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@westpac/ui",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -255,9 +255,9 @@
255
255
  "typescript": "^5.1.6",
256
256
  "vite": "^4.3.9",
257
257
  "vitest": "^0.30.1",
258
- "@westpac/ts-config": "~0.0.0",
259
- "@westpac/eslint-config": "~0.2.0",
260
- "@westpac/test-config": "~0.0.0"
258
+ "@westpac/eslint-config": "~0.2.1",
259
+ "@westpac/test-config": "~0.0.0",
260
+ "@westpac/ts-config": "~0.0.0"
261
261
  },
262
262
  "dependencies": {
263
263
  "@duetds/date-picker": "~1.4.0",
@@ -1,5 +1,7 @@
1
+ 'use client';
2
+
1
3
  import { clsx } from 'clsx';
2
- import * as React from 'react';
4
+ import React, { useMemo, useRef } from 'react';
3
5
  import { DismissButton, Overlay, usePopover } from 'react-aria';
4
6
 
5
7
  import { AutocompletePopoverProps } from './autocomplete-popover.types.js';
@@ -7,7 +9,7 @@ import { AutocompletePopoverProps } from './autocomplete-popover.types.js';
7
9
  * @private
8
10
  */
9
11
  export function AutocompletePopover(props: AutocompletePopoverProps) {
10
- const ref = React.useRef<HTMLDivElement>(null);
12
+ const ref = useRef<HTMLDivElement>(null);
11
13
  const { popoverRef = ref, state, children, className, isNonModal, portalContainer } = props;
12
14
  const { popoverProps, underlayProps } = usePopover(
13
15
  {
@@ -18,11 +20,17 @@ export function AutocompletePopover(props: AutocompletePopoverProps) {
18
20
  );
19
21
 
20
22
  // This is required so branding applies correctly by default due to portal location, can be overridden with portalContainer prop
21
- const brandContainer = document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]');
23
+ const brandContainer = useMemo(() => {
24
+ if (typeof window !== 'undefined') {
25
+ return (
26
+ document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]') || document.body
27
+ );
28
+ }
29
+ }, []);
22
30
 
23
31
  const width = props.triggerRef.current?.getBoundingClientRect().width;
24
32
  return (
25
- <Overlay portalContainer={portalContainer || brandContainer || document.body}>
33
+ <Overlay portalContainer={portalContainer || brandContainer}>
26
34
  {!isNonModal && <div {...underlayProps} className="fixed inset-0" />}
27
35
 
28
36
  <div
@@ -1,6 +1,6 @@
1
1
  import { clsx } from 'clsx';
2
2
  import { PanInfo, motion, useAnimation } from 'framer-motion';
3
- import React, { useCallback, useEffect, useRef, useState } from 'react';
3
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { Overlay, useModalOverlay } from 'react-aria';
5
5
 
6
6
  import { BREAKPOINTS } from '../../../../tailwind/constants/index.js';
@@ -30,7 +30,13 @@ export function BottomSheetModal({ state, height, width, children, portalContain
30
30
  const [isMobile, setIsMobile] = useState(checkIfItIsMobile(MEDIUM_BREAKPOINT_AS_NUMBER));
31
31
 
32
32
  // This is required so branding applies correctly by default due to portal location, can be overridden with portalContainer prop
33
- const brandContainer = document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]');
33
+ const brandContainer = useMemo(() => {
34
+ if (isBrowser) {
35
+ return (
36
+ document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]') || document.body
37
+ );
38
+ }
39
+ }, []);
34
40
 
35
41
  useEffect(() => {
36
42
  function handleResize() {
@@ -68,7 +74,7 @@ export function BottomSheetModal({ state, height, width, children, portalContain
68
74
  }
69
75
 
70
76
  return (
71
- <Overlay portalContainer={portalContainer || brandContainer || document.body}>
77
+ <Overlay portalContainer={portalContainer || brandContainer}>
72
78
  <div className={styles.underlay()} {...underlayProps}>
73
79
  <motion.div
74
80
  animate={controls}
@@ -1,4 +1,6 @@
1
- import React, { useRef } from 'react';
1
+ 'use client';
2
+
3
+ import React, { useMemo, useRef } from 'react';
2
4
  import { Overlay, useModalOverlay } from 'react-aria';
3
5
 
4
6
  import { styles as backdropStyles } from './modal-backdrop.styles.js';
@@ -15,16 +17,22 @@ export function ModalBackdrop({ zIndex = 100, portalContainer, size, ...props }:
15
17
 
16
18
  const { modalProps, underlayProps } = useModalOverlay(props, state, ref);
17
19
 
20
+ // This is required so branding applies correctly by default due to portal location, can be overridden with portalContainer prop
21
+ const brandContainer = useMemo(() => {
22
+ if (typeof window !== 'undefined') {
23
+ return (
24
+ document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]') || document.body
25
+ );
26
+ }
27
+ }, []);
28
+
18
29
  // Don't render anything if the modal is not open and we're not animating out.
19
30
  if (!state.isOpen) {
20
31
  return null;
21
32
  }
22
33
 
23
- // This is required so branding applies correctly by default due to portal location, can be overridden with portalContainer prop
24
- const brandContainer = document.querySelector('[data-theme]') || document.querySelector('[className="data-theme"]');
25
-
26
34
  return (
27
- <Overlay portalContainer={portalContainer || brandContainer || document.body}>
35
+ <Overlay portalContainer={portalContainer || brandContainer}>
28
36
  <div style={{ zIndex }} className={styles.base()} {...underlayProps}>
29
37
  <div {...modalProps} ref={ref} className={styles.modal()}>
30
38
  {children}
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
1
+ import React, { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
2
2
  import { FocusScope } from 'react-aria';
3
3
 
4
4
  import { Button } from '../../../button/index.js';
@@ -14,7 +14,12 @@ import { type PanelProps, Position } from './panel.types.js';
14
14
  export function Panel({ state, heading, headingTag: Tag = 'h1', content, placement, id, triggerRef }: PanelProps) {
15
15
  const popoverRef = useRef<HTMLDivElement>(null);
16
16
  const arrowRef = useRef<HTMLDivElement>(null);
17
- const remSize = parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
17
+ const remSize = useMemo(() => {
18
+ if (typeof window !== 'undefined') {
19
+ return parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
20
+ }
21
+ return 1;
22
+ }, []);
18
23
 
19
24
  const [position, setPosition] = useState<Position>({
20
25
  placement: 'top',
@@ -1,4 +1,4 @@
1
- import { RefObject } from 'react';
1
+ import { RefObject, useMemo } from 'react';
2
2
 
3
3
  import { Position } from './components/panel/panel.types.js';
4
4
 
@@ -16,7 +16,10 @@ export const usePopoverPosition = (
16
16
  const trigger = triggerRef.current.getBoundingClientRect();
17
17
  const popover = popoverRef.current.getBoundingClientRect();
18
18
  const arrow = arrowRef.current.getBoundingClientRect();
19
- const remSize = parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
19
+ const remSize =
20
+ typeof window !== 'undefined'
21
+ ? parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize)
22
+ : 1;
20
23
 
21
24
  const position: Position = {
22
25
  placement: placement ? placement : 'top',