@khanacademy/wonder-blocks-popover 7.0.2 → 7.1.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,30 @@
1
1
  # @khanacademy/wonder-blocks-popover
2
2
 
3
+ ## 7.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8e11e83: Popover's close button now reads its default `aria-label` ("Close Popover") from `WonderBlocksConfigProvider`. The `closeButtonLabel` prop on PopoverContent and PopoverContentCore overrides the built-in translation.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [6bd5d0c]
12
+ - Updated dependencies [8e11e83]
13
+ - @khanacademy/wonder-blocks-config@0.5.0
14
+ - @khanacademy/wonder-blocks-floating@0.2.1
15
+
16
+ ## 7.0.3
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [cbdc909]
21
+ - @khanacademy/wonder-blocks-tokens@18.1.0
22
+ - @khanacademy/wonder-blocks-floating@0.2.1
23
+ - @khanacademy/wonder-blocks-icon-button@12.0.2
24
+ - @khanacademy/wonder-blocks-layout@3.2.1
25
+ - @khanacademy/wonder-blocks-styles@0.4.1
26
+ - @khanacademy/wonder-blocks-typography@5.0.6
27
+
3
28
  ## 7.0.2
4
29
 
5
30
  ### Patch Changes
@@ -51,7 +51,8 @@ declare const PopoverContentCore: React.ForwardRefExoticComponent<Readonly<impor
51
51
  */
52
52
  closeButtonLight?: boolean;
53
53
  /**
54
- * Close button label for use in screen readers
54
+ * Close button label for use in screen readers. This overrides the default
55
+ * label provided by `WonderBlocksConfigProvider`.
55
56
  */
56
57
  closeButtonLabel?: string;
57
58
  /**
@@ -44,7 +44,8 @@ declare const PopoverContent: React.ForwardRefExoticComponent<Readonly<import("@
44
44
  close: () => unknown;
45
45
  }) => React.ReactElement);
46
46
  /**
47
- * Close button label for use in screen readers
47
+ * Close button label for use in screen readers. This overrides the default
48
+ * label provided by `WonderBlocksConfigProvider`.
48
49
  */
49
50
  closeButtonLabel?: string;
50
51
  /**
package/dist/es/index.js CHANGED
@@ -9,6 +9,7 @@ import { ScrollableView } from '@khanacademy/wonder-blocks-layout';
9
9
  import { actionStyles } from '@khanacademy/wonder-blocks-styles';
10
10
  import xIcon from '@phosphor-icons/core/regular/x.svg';
11
11
  import IconButton from '@khanacademy/wonder-blocks-icon-button';
12
+ import { useWonderBlocksI18n } from '@khanacademy/wonder-blocks-config';
12
13
 
13
14
  const defaultContext={close:undefined,placement:"top"};const PopoverContext=React.createContext(defaultContext);PopoverContext.displayName="PopoverContext";
14
15
 
@@ -18,7 +19,7 @@ const PopoverDialog=React.forwardRef(function PopoverDialog(props,ref){const{chi
18
19
 
19
20
  function Popover(props){const{children,content,placement:placementProp="top",dismissEnabled,id,closedFocusId,initialFocusId,opened:openedProp,onClose,showTail=true,portal=true,rootBoundary="viewport",viewportPadding,testId,"aria-label":ariaLabel,"aria-describedby":ariaDescribedBy}=props;const isControlled=typeof openedProp==="boolean";const[internalOpened,setInternalOpened]=React.useState(!!openedProp);const opened=isControlled?openedProp:internalOpened;const[placement,setPlacement]=React.useState(placementProp);const initialFocusRef=React.useRef(null);const returnFocusRef=React.useRef(null);const closeFiredRef=React.useRef(false);const generatedUniqueId=React.useId();const uniqueId=id??generatedUniqueId;React.useEffect(()=>{if(opened&&closedFocusId){returnFocusRef.current=document.getElementById(closedFocusId);}},[opened,closedFocusId]);const handleOpenChange=React.useCallback(nextOpened=>{if(!isControlled){setInternalOpened(nextOpened);}if(nextOpened){closeFiredRef.current=false;}else if(!closeFiredRef.current){closeFiredRef.current=true;onClose?.();}},[isControlled,onClose]);const handleClose=React.useCallback(()=>{handleOpenChange(false);},[handleOpenChange]);const handleAnchorClick=React.useCallback(()=>{if(!opened){handleOpenChange(true);}else if(dismissEnabled){handleOpenChange(false);}},[opened,dismissEnabled,handleOpenChange]);const handlePlacementChange=React.useCallback(nextPlacement=>{setPlacement(nextPlacement.split("-")[0]);},[]);const handleDialogRef=React.useCallback(node=>{if(node&&initialFocusId){initialFocusRef.current=node.querySelector(`#${initialFocusId}`);}},[initialFocusId]);const renderContent=()=>{const popoverContents=typeof content==="function"?content({close:handleClose}):content;return React.cloneElement(popoverContents,{uniqueId})};const describedBy=ariaDescribedBy||`${uniqueId}-content`;const ariaLabelledBy=ariaLabel?undefined:`${uniqueId}-title`;const dialog=jsx(PopoverDialog,{ref:handleDialogRef,id:uniqueId,placement:placement,"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,"aria-describedby":describedBy,children:renderContent()});return jsx(PopoverContext.Provider,{value:{close:handleClose,placement:placement,"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy},children:jsx(Floating,{open:opened,strategy:"fixed",onOpenChange:handleOpenChange,placement:placementProp,onPlacementChange:handlePlacementChange,content:dialog,constrainSize:true,dismissEnabled:!!dismissEnabled,closeOnFocusOut:!!dismissEnabled,showArrow:showTail,portal:portal,rootBoundary:rootBoundary,shiftPadding:viewportPadding,initialFocusRef:initialFocusId?initialFocusRef:undefined,returnFocus:closedFocusId?returnFocusRef:true,testId:testId,children:jsx(PopoverAnchor,{id:`${uniqueId}-anchor`,"aria-controls":uniqueId,"aria-expanded":opened?"true":"false",onClick:handleAnchorClick,children:children})})})}
20
21
 
21
- const CloseButton=props=>{const{"aria-label":ariaLabel="Close Popover",style,testId}=props;const{close}=React.useContext(PopoverContext);return jsx(IconButton,{icon:xIcon,"aria-label":ariaLabel,onClick:close,kind:"tertiary",actionType:"neutral",style:style,testId:testId})};
22
+ const CloseButton=props=>{const{strings}=useWonderBlocksI18n();const{"aria-label":ariaLabel,style,testId}=props;const{close}=React.useContext(PopoverContext);return jsx(IconButton,{icon:xIcon,"aria-label":ariaLabel||strings.iconAltClosePopover,onClick:close,kind:"tertiary",actionType:"neutral",style:style,testId:testId})};
22
23
 
23
24
  const PopoverContentCore=React.forwardRef(function PopoverContentCore({"aria-label":ariaLabel,children,closeButtonLight=false,closeButtonLabel,closeButtonVisible=false,style,testId},ref){const popoverContext=React.useContext(PopoverContext);const labelProps=ariaLabel?{"aria-label":ariaLabel}:{"aria-label":popoverContext["aria-label"],"aria-labelledby":popoverContext["aria-labelledby"]};return jsx(ScrollableView,{...labelProps,style:styles$1.scrollableView,children:jsxs(View,{testId:testId,style:[styles$1.content,style],ref:ref,children:[closeButtonVisible&&jsx(CloseButton,{"aria-label":closeButtonLabel,style:[styles$1.closeButton,closeButtonLight&&actionStyles.inverse],testId:`${testId||"popover"}-close-btn`}),children]})})});PopoverContentCore.displayName="PopoverContentCore";const styles$1=StyleSheet.create({scrollableView:{borderRadius:`calc(${border.radius.radius_040} - ${border.width.thin})`},content:{margin:0,maxInlineSize:`calc(${sizing.size_160} * 18)`,padding:sizing.size_240,overflow:"hidden",justifyContent:"center",flexShrink:0},closeButton:{margin:0,position:"absolute",insetInlineEnd:sizing.size_040,insetBlockStart:sizing.size_040,zIndex:1}});
24
25
 
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ var wonderBlocksLayout = require('@khanacademy/wonder-blocks-layout');
13
13
  var wonderBlocksStyles = require('@khanacademy/wonder-blocks-styles');
14
14
  var xIcon = require('@phosphor-icons/core/regular/x.svg');
15
15
  var IconButton = require('@khanacademy/wonder-blocks-icon-button');
16
+ var wonderBlocksConfig = require('@khanacademy/wonder-blocks-config');
16
17
 
17
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
19
 
@@ -46,7 +47,7 @@ const PopoverDialog=React__namespace.forwardRef(function PopoverDialog(props,ref
46
47
 
47
48
  function Popover(props){const{children,content,placement:placementProp="top",dismissEnabled,id,closedFocusId,initialFocusId,opened:openedProp,onClose,showTail=true,portal=true,rootBoundary="viewport",viewportPadding,testId,"aria-label":ariaLabel,"aria-describedby":ariaDescribedBy}=props;const isControlled=typeof openedProp==="boolean";const[internalOpened,setInternalOpened]=React__namespace.useState(!!openedProp);const opened=isControlled?openedProp:internalOpened;const[placement,setPlacement]=React__namespace.useState(placementProp);const initialFocusRef=React__namespace.useRef(null);const returnFocusRef=React__namespace.useRef(null);const closeFiredRef=React__namespace.useRef(false);const generatedUniqueId=React__namespace.useId();const uniqueId=id??generatedUniqueId;React__namespace.useEffect(()=>{if(opened&&closedFocusId){returnFocusRef.current=document.getElementById(closedFocusId);}},[opened,closedFocusId]);const handleOpenChange=React__namespace.useCallback(nextOpened=>{if(!isControlled){setInternalOpened(nextOpened);}if(nextOpened){closeFiredRef.current=false;}else if(!closeFiredRef.current){closeFiredRef.current=true;onClose?.();}},[isControlled,onClose]);const handleClose=React__namespace.useCallback(()=>{handleOpenChange(false);},[handleOpenChange]);const handleAnchorClick=React__namespace.useCallback(()=>{if(!opened){handleOpenChange(true);}else if(dismissEnabled){handleOpenChange(false);}},[opened,dismissEnabled,handleOpenChange]);const handlePlacementChange=React__namespace.useCallback(nextPlacement=>{setPlacement(nextPlacement.split("-")[0]);},[]);const handleDialogRef=React__namespace.useCallback(node=>{if(node&&initialFocusId){initialFocusRef.current=node.querySelector(`#${initialFocusId}`);}},[initialFocusId]);const renderContent=()=>{const popoverContents=typeof content==="function"?content({close:handleClose}):content;return React__namespace.cloneElement(popoverContents,{uniqueId})};const describedBy=ariaDescribedBy||`${uniqueId}-content`;const ariaLabelledBy=ariaLabel?undefined:`${uniqueId}-title`;const dialog=jsxRuntime.jsx(PopoverDialog,{ref:handleDialogRef,id:uniqueId,placement:placement,"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,"aria-describedby":describedBy,children:renderContent()});return jsxRuntime.jsx(PopoverContext.Provider,{value:{close:handleClose,placement:placement,"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy},children:jsxRuntime.jsx(wonderBlocksFloating.Floating,{open:opened,strategy:"fixed",onOpenChange:handleOpenChange,placement:placementProp,onPlacementChange:handlePlacementChange,content:dialog,constrainSize:true,dismissEnabled:!!dismissEnabled,closeOnFocusOut:!!dismissEnabled,showArrow:showTail,portal:portal,rootBoundary:rootBoundary,shiftPadding:viewportPadding,initialFocusRef:initialFocusId?initialFocusRef:undefined,returnFocus:closedFocusId?returnFocusRef:true,testId:testId,children:jsxRuntime.jsx(PopoverAnchor,{id:`${uniqueId}-anchor`,"aria-controls":uniqueId,"aria-expanded":opened?"true":"false",onClick:handleAnchorClick,children:children})})})}
48
49
 
49
- const CloseButton=props=>{const{"aria-label":ariaLabel="Close Popover",style,testId}=props;const{close}=React__namespace.useContext(PopoverContext);return jsxRuntime.jsx(IconButton__default["default"],{icon:xIcon__default["default"],"aria-label":ariaLabel,onClick:close,kind:"tertiary",actionType:"neutral",style:style,testId:testId})};
50
+ const CloseButton=props=>{const{strings}=wonderBlocksConfig.useWonderBlocksI18n();const{"aria-label":ariaLabel,style,testId}=props;const{close}=React__namespace.useContext(PopoverContext);return jsxRuntime.jsx(IconButton__default["default"],{icon:xIcon__default["default"],"aria-label":ariaLabel||strings.iconAltClosePopover,onClick:close,kind:"tertiary",actionType:"neutral",style:style,testId:testId})};
50
51
 
51
52
  const PopoverContentCore=React__namespace.forwardRef(function PopoverContentCore({"aria-label":ariaLabel,children,closeButtonLight=false,closeButtonLabel,closeButtonVisible=false,style,testId},ref){const popoverContext=React__namespace.useContext(PopoverContext);const labelProps=ariaLabel?{"aria-label":ariaLabel}:{"aria-label":popoverContext["aria-label"],"aria-labelledby":popoverContext["aria-labelledby"]};return jsxRuntime.jsx(wonderBlocksLayout.ScrollableView,{...labelProps,style:styles$1.scrollableView,children:jsxRuntime.jsxs(wonderBlocksCore.View,{testId:testId,style:[styles$1.content,style],ref:ref,children:[closeButtonVisible&&jsxRuntime.jsx(CloseButton,{"aria-label":closeButtonLabel,style:[styles$1.closeButton,closeButtonLight&&wonderBlocksStyles.actionStyles.inverse],testId:`${testId||"popover"}-close-btn`}),children]})})});PopoverContentCore.displayName="PopoverContentCore";const styles$1=aphrodite.StyleSheet.create({scrollableView:{borderRadius:`calc(${wonderBlocksTokens.border.radius.radius_040} - ${wonderBlocksTokens.border.width.thin})`},content:{margin:0,maxInlineSize:`calc(${wonderBlocksTokens.sizing.size_160} * 18)`,padding:wonderBlocksTokens.sizing.size_240,overflow:"hidden",justifyContent:"center",flexShrink:0},closeButton:{margin:0,position:"absolute",insetInlineEnd:wonderBlocksTokens.sizing.size_040,insetBlockStart:wonderBlocksTokens.sizing.size_040,zIndex:1}});
52
53
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "7.0.2",
6
+ "version": "7.1.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -20,13 +20,14 @@
20
20
  "module": "dist/es/index.js",
21
21
  "types": "dist/index.d.ts",
22
22
  "dependencies": {
23
+ "@khanacademy/wonder-blocks-config": "0.5.0",
23
24
  "@khanacademy/wonder-blocks-core": "12.5.0",
24
- "@khanacademy/wonder-blocks-floating": "0.2.0",
25
- "@khanacademy/wonder-blocks-layout": "3.2.0",
26
- "@khanacademy/wonder-blocks-styles": "0.4.0",
27
- "@khanacademy/wonder-blocks-icon-button": "12.0.1",
28
- "@khanacademy/wonder-blocks-tokens": "18.0.0",
29
- "@khanacademy/wonder-blocks-typography": "5.0.5"
25
+ "@khanacademy/wonder-blocks-floating": "0.2.1",
26
+ "@khanacademy/wonder-blocks-icon-button": "12.0.2",
27
+ "@khanacademy/wonder-blocks-layout": "3.2.1",
28
+ "@khanacademy/wonder-blocks-styles": "0.4.1",
29
+ "@khanacademy/wonder-blocks-tokens": "18.1.0",
30
+ "@khanacademy/wonder-blocks-typography": "5.0.6"
30
31
  },
31
32
  "peerDependencies": {
32
33
  "@phosphor-icons/core": "^2.0.2",