@mrshmllw/smores-react 16.10.5 → 16.10.7

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.
@@ -22,7 +22,7 @@ export const Accordion = ({ title, children, onToggle, filledBackground, default
22
22
  };
23
23
  const Wrapper = styled(Box)(({ $borderTop, $fullBorder, $filledBackground, $borderColor, $backgroundColor, }) => css `
24
24
  border-bottom: 1px solid ${$borderColor};
25
- ${$borderTop && `border-top: 1px solid ${$backgroundColor};`}
25
+ ${$borderTop && `border-top: 1px solid ${$borderColor};`}
26
26
 
27
27
  ${$fullBorder &&
28
28
  css `
@@ -1 +1 @@
1
- {"version":3,"file":"Accordion.js","sourceRoot":"","sources":["../../src/Accordion/Accordion.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAiB,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGzD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAY,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAA;AAwBhF,MAAM,CAAC,MAAM,SAAS,GAAuB,CAAC,EAC5C,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,aAAa,GAAG,KAAK,EACrB,SAAS,GAAG,KAAK,EACjB,WAAW,GAAG,gCAAgC,EAC9C,eAAe,GAAG,wBAAwB,EAC1C,QAAQ,EACR,UAAU,GAAG,KAAK,EAClB,GAAG,WAAW,EACf,EAAE,EAAE;IACH,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA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AC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,GAC5C,GACQ,IACC,EACd,MAAM,IAAI,CACT,KAAC,GAAG,IAAC,EAAE,EAAC,WAAW,EAAC,EAAE,EAAC,WAAW,EAAC,EAAE,EAAE,EAAE,YACtC,QAAQ,GACL,CACP,IACO,CACX,CAAA;AACH,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAKzB,CAAC,EACC,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,GACjB,EAAE,EAAE,CAAC,GAAG,CAAA;+BACoB,YAAY;MACrC,UAAU,IAAI,yBAAyB,gBAAgB,GAAG;;MAG1D,WAAW;IACX,GAAG,CAAA;4BACmB,YAAY;;OAGpC;;MAGE,iBAAiB;IACjB,GAAG,CAAA;4BACmB,gBAAgB;OAExC;GACD,CACF,CAAA;AAED,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAA;;;CAGhC,CAAA;AACD,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;CAE/B,CAAA;AAED,MAAM,SAAS,GAAG,MAAM,CAAC,aAAa,CAAC,CAGrC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;iBACL,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,cAAc;;GAEzD,CACF,CAAA","sourcesContent":["import { FC, ReactNode, useState } from 'react'\nimport styled, { css, useTheme } from 'styled-components'\n\nimport { TransientProps } from '../utils/utilTypes'\nimport { Box } from '../Box'\nimport { Text } from '../Text'\nimport { MarginProps } from '../utils/space'\nimport { NewColor, resolveToThemeColor } from '../ThemeProvider/utils/colourMap'\nimport { IconContainer } from '../sharedStyles/shared.styles'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { faChevronDown } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\n\ntype UsableNewColors = Extract<\n NewColor,\n | 'color.surface.base.000'\n | 'color.surface.base.100'\n | 'color.surface.base.300'\n | 'color.illustration.neutral.300'\n>\n\nexport type AccordionProps = {\n title: string\n subTitle?: string\n filledBackground?: boolean\n borderTop?: boolean\n borderColor?: 'oatmeal' | 'custard' | 'cream' | 'coconut' | UsableNewColors\n fullBorder?: boolean\n backgroundColor?:\n 'oatmeal' | 'custard' | 'cream' | 'coconut' | UsableNewColors\n onToggle?: (isOpen: boolean) => void\n children: ReactNode\n defaultIsOpen?: boolean\n} & MarginProps\n\nexport const Accordion: FC<AccordionProps> = ({\n title,\n children,\n onToggle,\n filledBackground,\n defaultIsOpen = false,\n borderTop = false,\n borderColor = 'color.illustration.neutral.300',\n backgroundColor = 'color.surface.base.300',\n subTitle,\n fullBorder = false,\n ...marginProps\n}) => {\n const theme = useTheme()\n const [isOpen, setIsOpen] = useState(defaultIsOpen)\n const px = fullBorder ? '16px' : '0'\n\n const resolvedBorderColor = resolveToThemeColor(borderColor, theme)\n\n const resolvedBackgroundColour = resolveToThemeColor(backgroundColor, theme)\n\n const handleToggle = () => {\n const nextOpenState = !isOpen\n onToggle?.(nextOpenState)\n setIsOpen(nextOpenState)\n }\n\n return (\n <Wrapper\n $borderTop={borderTop}\n $fullBorder={fullBorder}\n $filledBackground={filledBackground}\n $borderColor={resolvedBorderColor}\n $backgroundColor={resolvedBackgroundColour}\n {...marginProps}\n >\n <TopContainer\n flex\n alignItems=\"center\"\n justifyContent=\"space-between\"\n onClick={handleToggle}\n py=\"space.200\"\n pr=\"space.200\"\n pl={px}\n >\n <TitleContainer>\n <Text tag=\"h2\" typo=\"headline-regular\">\n {title}\n </Text>\n {subTitle && (\n <Text tag=\"label\" typo=\"label\" mt=\"space.050\">\n {subTitle}\n </Text>\n )}\n </TitleContainer>\n\n <CaretIcon $size={20} $isOpen={isOpen} $borderTop={borderTop}>\n <FontAwesomeIcon\n icon={faChevronDown}\n color={theme.color.illustration.neutral[400]}\n />\n </CaretIcon>\n </TopContainer>\n {isOpen && (\n <Box pt=\"space.150\" pb=\"space.200\" px={px}>\n {children}\n </Box>\n )}\n </Wrapper>\n )\n}\n\nconst Wrapper = styled(Box)<\n TransientProps<\n Pick<AccordionProps, 'borderTop' | 'fullBorder' | 'filledBackground'>\n > & { $borderColor: string; $backgroundColor: string }\n>(\n ({\n $borderTop,\n $fullBorder,\n $filledBackground,\n $borderColor,\n $backgroundColor,\n }) => css`\n border-bottom: 1px solid ${$borderColor};\n ${$borderTop && `border-top: 1px solid ${$backgroundColor};`}\n\n ${\n $fullBorder &&\n css`\n border: 1px solid ${$borderColor};\n border-radius: 16px;\n `\n }\n\n ${\n $filledBackground &&\n css`\n background-color: ${$backgroundColor};\n `\n }\n `,\n)\n\nconst TitleContainer = styled.div`\n display: flex;\n flex-direction: column;\n`\nconst TopContainer = styled(Box)`\n cursor: pointer;\n`\n\nconst CaretIcon = styled(IconContainer)<\n TransientProps<Pick<AccordionProps, 'borderTop'>> & { $isOpen: boolean }\n>(\n ({ $isOpen }) => css`\n transform: ${$isOpen ? 'rotate(180deg)' : 'rotate(0deg)'};\n transition: transform 0.6s ease;\n `,\n)\n"]}
1
+ {"version":3,"file":"Accordion.js","sourceRoot":"","sources":["../../src/Accordion/Accordion.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAiB,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGzD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAY,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAA;AAwBhF,MAAM,CAAC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led-components'\n\nimport { TransientProps } from '../utils/utilTypes'\nimport { Box } from '../Box'\nimport { Text } from '../Text'\nimport { MarginProps } from '../utils/space'\nimport { NewColor, resolveToThemeColor } from '../ThemeProvider/utils/colourMap'\nimport { IconContainer } from '../sharedStyles/shared.styles'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { faChevronDown } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\n\ntype UsableNewColors = Extract<\n NewColor,\n | 'color.surface.base.000'\n | 'color.surface.base.100'\n | 'color.surface.base.300'\n | 'color.illustration.neutral.300'\n>\n\nexport type AccordionProps = {\n title: string\n subTitle?: string\n filledBackground?: boolean\n borderTop?: boolean\n borderColor?: 'oatmeal' | 'custard' | 'cream' | 'coconut' | UsableNewColors\n fullBorder?: boolean\n backgroundColor?:\n 'oatmeal' | 'custard' | 'cream' | 'coconut' | UsableNewColors\n onToggle?: (isOpen: boolean) => void\n children: ReactNode\n defaultIsOpen?: boolean\n} & MarginProps\n\nexport const Accordion: FC<AccordionProps> = ({\n title,\n children,\n onToggle,\n filledBackground,\n defaultIsOpen = false,\n borderTop = false,\n borderColor = 'color.illustration.neutral.300',\n backgroundColor = 'color.surface.base.300',\n subTitle,\n fullBorder = false,\n ...marginProps\n}) => {\n const theme = useTheme()\n const [isOpen, setIsOpen] = useState(defaultIsOpen)\n const px = fullBorder ? '16px' : '0'\n\n const resolvedBorderColor = resolveToThemeColor(borderColor, theme)\n\n const resolvedBackgroundColour = resolveToThemeColor(backgroundColor, theme)\n\n const handleToggle = () => {\n const nextOpenState = !isOpen\n onToggle?.(nextOpenState)\n setIsOpen(nextOpenState)\n }\n\n return (\n <Wrapper\n $borderTop={borderTop}\n $fullBorder={fullBorder}\n $filledBackground={filledBackground}\n $borderColor={resolvedBorderColor}\n $backgroundColor={resolvedBackgroundColour}\n {...marginProps}\n >\n <TopContainer\n flex\n alignItems=\"center\"\n justifyContent=\"space-between\"\n onClick={handleToggle}\n py=\"space.200\"\n pr=\"space.200\"\n pl={px}\n >\n <TitleContainer>\n <Text tag=\"h2\" typo=\"headline-regular\">\n {title}\n </Text>\n {subTitle && (\n <Text tag=\"label\" typo=\"label\" mt=\"space.050\">\n {subTitle}\n </Text>\n )}\n </TitleContainer>\n\n <CaretIcon $size={20} $isOpen={isOpen} $borderTop={borderTop}>\n <FontAwesomeIcon\n icon={faChevronDown}\n color={theme.color.illustration.neutral[400]}\n />\n </CaretIcon>\n </TopContainer>\n {isOpen && (\n <Box pt=\"space.150\" pb=\"space.200\" px={px}>\n {children}\n </Box>\n )}\n </Wrapper>\n )\n}\n\nconst Wrapper = styled(Box)<\n TransientProps<\n Pick<AccordionProps, 'borderTop' | 'fullBorder' | 'filledBackground'>\n > & { $borderColor: string; $backgroundColor: string }\n>(\n ({\n $borderTop,\n $fullBorder,\n $filledBackground,\n $borderColor,\n $backgroundColor,\n }) => css`\n border-bottom: 1px solid ${$borderColor};\n ${$borderTop && `border-top: 1px solid ${$borderColor};`}\n\n ${\n $fullBorder &&\n css`\n border: 1px solid ${$borderColor};\n border-radius: 16px;\n `\n }\n\n ${\n $filledBackground &&\n css`\n background-color: ${$backgroundColor};\n `\n }\n `,\n)\n\nconst TitleContainer = styled.div`\n display: flex;\n flex-direction: column;\n`\nconst TopContainer = styled(Box)`\n cursor: pointer;\n`\n\nconst CaretIcon = styled(IconContainer)<\n TransientProps<Pick<AccordionProps, 'borderTop'>> & { $isOpen: boolean }\n>(\n ({ $isOpen }) => css`\n transform: ${$isOpen ? 'rotate(180deg)' : 'rotate(0deg)'};\n transition: transform 0.6s ease;\n `,\n)\n"]}
@@ -1,23 +1,64 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
2
+ import { useId, useRef, useState } from 'react';
3
3
  import styled, { css, useTheme } from 'styled-components';
4
4
  import { Box } from '../Box';
5
5
  import { Text } from '../Text';
6
- import { List } from './List';
6
+ import { ListContainer, ListItems } from './List';
7
7
  import { resolveToThemeColor } from '../ThemeProvider/utils/colourMap';
8
- import { faChevronDown } from '@awesome.me/kit-46ca99185c/icons/classic/regular';
8
+ import { faChevronDown } from '@awesome.me/kit-46ca99185c/icons/classic/solid';
9
9
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
10
10
  import { IconContainer } from '../sharedStyles/shared.styles';
11
- export const ActionDropdown = ({ id, className = '', label, value, list, onSelect, ...marginProps }) => {
11
+ import { FloatingFocusManager, useClick, useDismiss, useFloating, useInteractions, useListNavigation, useRole, } from '@floating-ui/react';
12
+ import { focusOutlineStyle } from '../utils/focusOutline';
13
+ export const ActionDropdown = ({ id: idProp, className = '', label, value, list, onSelect, ...marginProps }) => {
12
14
  const [open, setOpen] = useState(false);
15
+ const [activeIndex, setActiveIndex] = useState(null);
16
+ const listRef = useRef([]);
17
+ const generatedId = useId();
18
+ const id = idProp ?? generatedId;
19
+ const buttonId = `${id}-button`;
13
20
  const theme = useTheme();
14
21
  const resolvedBgColor = resolveToThemeColor(value.bgColor ?? 'color.background.100', theme);
15
22
  const resolvedTextColor = resolveToThemeColor(value.textColor ?? 'color.text.base', theme);
16
- return (_jsxs(Container, { id: id, className: className, onClick: () => setOpen((currentOpen) => !currentOpen), ...marginProps, children: [label && (_jsx(Text, { tag: "label", color: "sesame", typo: "label", children: label })), _jsxs(Label, { $text: resolvedTextColor, $bg: resolvedBgColor, children: [_jsx(SelectedOption, { children: value.label }), _jsx(IconContainer, { $size: 20, style: {
23
+ const { refs, context } = useFloating({
24
+ open,
25
+ onOpenChange: (nextOpen) => {
26
+ setOpen(nextOpen);
27
+ if (!nextOpen)
28
+ setActiveIndex(null);
29
+ },
30
+ });
31
+ const click = useClick(context);
32
+ const dismiss = useDismiss(context);
33
+ const role = useRole(context, { role: 'listbox' });
34
+ const listNavigation = useListNavigation(context, {
35
+ listRef,
36
+ activeIndex,
37
+ selectedIndex: list.findIndex((item) => item.value === value.value),
38
+ onNavigate: setActiveIndex,
39
+ loop: true,
40
+ });
41
+ const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([click, dismiss, role, listNavigation]);
42
+ const selectOption = (option) => {
43
+ onSelect(option);
44
+ setOpen(false);
45
+ setActiveIndex(null);
46
+ };
47
+ const handleListKeyDown = (event) => {
48
+ if ((event.key === 'Enter' || event.key === ' ') && activeIndex !== null) {
49
+ event.preventDefault();
50
+ selectOption(list[activeIndex]);
51
+ }
52
+ };
53
+ return (_jsxs(Container, { id: idProp, className: className, ...marginProps, children: [label && (_jsx(Text, { tag: "label", htmlFor: buttonId, color: "sesame", typo: "label", children: label })), _jsxs(Label, { ref: refs.setReference, id: buttonId, type: "button", "aria-label": label ? undefined : 'Select an option', $text: resolvedTextColor, $bg: resolvedBgColor, ...getReferenceProps(), children: [_jsx(SelectedOption, { children: value.label }), _jsx(IconContainer, { $size: 20, style: {
17
54
  rotate: open ? '180deg' : '0deg',
18
- }, children: _jsx(FontAwesomeIcon, { icon: faChevronDown, color: resolvedTextColor }) })] }), _jsx(OuterContainer, { open: open, children: _jsx(List, { options: list, selectOption: onSelect }) })] }));
55
+ }, children: _jsx(FontAwesomeIcon, { icon: faChevronDown, color: resolvedTextColor }) })] }), _jsx(OuterContainer, { open: open, children: open && (_jsx(FloatingFocusManager, { context: context, modal: false, returnFocus: true, children: _jsx(ListContainer
56
+ // oxlint-disable-next-line react/react-compiler
57
+ , {
58
+ // oxlint-disable-next-line react/react-compiler
59
+ ref: refs.setFloating, ...getFloatingProps({ onKeyDown: handleListKeyDown }), children: _jsx(ListItems, { options: list, selectedValue: value.value, activeIndex: activeIndex, listRef: listRef, getItemProps: getItemProps, onSelect: selectOption }) }) })) })] }));
19
60
  };
20
- const Label = styled.div(({ $text, $bg }) => css `
61
+ const Label = styled.button(({ $text, $bg }) => css `
21
62
  color: ${$text};
22
63
  background-color: ${$bg};
23
64
  position: relative;
@@ -27,10 +68,14 @@ const Label = styled.div(({ $text, $bg }) => css `
27
68
  align-items: center;
28
69
  justify-content: space-between;
29
70
  text-align: center;
71
+ border: 0;
30
72
  border-radius: 100px;
31
73
  padding: 16px 16px 14px;
32
74
  box-sizing: border-box;
75
+ font: inherit;
76
+ cursor: pointer;
33
77
  user-select: none;
78
+ ${focusOutlineStyle}
34
79
  `);
35
80
  const SelectedOption = styled.span `
36
81
  font-size: 14px;
@@ -44,8 +89,6 @@ const Container = styled(Box) `
44
89
  width: 210px;
45
90
  height: 48px;
46
91
  text-align: center;
47
- cursor: pointer;
48
- outline: none;
49
92
  border-radius: 8px;
50
93
  `;
51
94
  const OuterContainer = styled.div(({ open }) => css `
@@ -1 +1 @@
1
- {"version":3,"file":"ActionDropdown.js","sourceRoot":"","sources":["../../src/ActionDropdown/ActionDropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,QAAQ,EAAE,MAAM,OAAO,CAAA;AACpC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAkB,IAAI,EAAE,MAAM,QAAQ,CAAA;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAe7D,MAAM,CAAC,MAAM,cAAc,GAA4B,CAAC,EACtD,EAAE,EACF,SAAS,GAAG,EAAE,EACd,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,GAAG,WAAW,EACf,EAAE,EAAE;IACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEvC,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IAExB,MAAM,eAAe,GAAG,mB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M,CAAC,GAAG,CAAC,CAAA;;;;;;;;;CAS5B,CAAA;AAMD,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAC/B,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,CAAA;;;;kBAID,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;eAClC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;kBACpB,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;wBACjB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;kBAClD,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;;;GAGvC,CACF,CAAA","sourcesContent":["import { FC, useState } from 'react'\nimport styled, { css, useTheme } from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Text } from '../Text'\nimport { ActionListItem, List } from './List'\n\nimport { MarginProps } from '../utils/space'\nimport { resolveToThemeColor } from '../ThemeProvider/utils/colourMap'\nimport { faChevronDown } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { IconContainer } from '../sharedStyles/shared.styles'\n\nexport type ActionDropdownProps = {\n id?: string\n className?: string\n /** label displayed above the dropdown */\n label?: string\n /** value */\n value: ActionListItem\n /** list of items for the dropdown list */\n list: ActionListItem[]\n /** onSelect handler */\n onSelect: (action: ActionListItem) => void\n} & MarginProps\n\nexport const ActionDropdown: FC<ActionDropdownProps> = ({\n id,\n className = '',\n label,\n value,\n list,\n onSelect,\n ...marginProps\n}) => {\n const [open, setOpen] = useState(false)\n\n const theme = useTheme()\n\n const resolvedBgColor = resolveToThemeColor(\n value.bgColor ?? 'color.background.100',\n theme,\n )\n const resolvedTextColor = resolveToThemeColor(\n value.textColor ?? 'color.text.base',\n theme,\n )\n\n return (\n <Container\n id={id}\n className={className}\n onClick={() => setOpen((currentOpen) => !currentOpen)}\n {...marginProps}\n >\n {label && (\n <Text tag=\"label\" color=\"sesame\" typo=\"label\">\n {label}\n </Text>\n )}\n\n <Label $text={resolvedTextColor} $bg={resolvedBgColor}>\n <SelectedOption>{value.label}</SelectedOption>\n <IconContainer\n $size={20}\n style={{\n rotate: open ? '180deg' : '0deg',\n }}\n >\n <FontAwesomeIcon icon={faChevronDown} color={resolvedTextColor} />\n </IconContainer>\n </Label>\n <OuterContainer open={open}>\n <List options={list} selectOption={onSelect} />\n </OuterContainer>\n </Container>\n )\n}\n\ninterface ISelected {\n $text: string\n $bg: string\n}\n\nconst Label = styled.div<ISelected>(\n ({ $text, $bg }) => css`\n color: ${$text};\n background-color: ${$bg};\n position: relative;\n width: 100%;\n height: 48px;\n display: flex;\n align-items: center;\n justify-content: space-between;\n text-align: center;\n border-radius: 100px;\n padding: 16px 16px 14px;\n box-sizing: border-box;\n user-select: none;\n `,\n)\n\nconst SelectedOption = styled.span`\n font-size: 14px;\n font-weight: bold;\n white-space: nowrap;\n text-overflow: ellipsis;\n`\n\nconst Container = styled(Box)`\n position: relative;\n display: block;\n width: 210px;\n height: 48px;\n text-align: center;\n cursor: pointer;\n outline: none;\n border-radius: 8px;\n`\n\ninterface IOpen {\n open: boolean\n}\n\nconst OuterContainer = styled.div<IOpen>(\n ({ open }) => css`\n position: absolute;\n width: 100%;\n border-radius: 12px;\n margin-top: ${({ theme }) => theme.space[100]};\n display: ${open ? 'block' : 'none'};\n max-height: ${open ? '235px' : '48px'};\n background-color: ${({ theme }) => theme.color.surface.base[300]};\n overflow-y: ${open ? 'auto' : 'hidden'};\n z-index: 4;\n transition: all 0.2s ease-in-out;\n `,\n)\n"]}
1
+ {"version":3,"file":"ActionDropdown.js","sourceRoot":"","sources":["../../src/ActionDropdown/ActionDropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,KAAK,E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styled-components'\n\nimport { Box } from '../Box'\nimport { Text } from '../Text'\nimport { ActionListItem, ListContainer, ListItems } from './List'\n\nimport { MarginProps } from '../utils/space'\nimport { resolveToThemeColor } from '../ThemeProvider/utils/colourMap'\nimport { faChevronDown } from '@awesome.me/kit-46ca99185c/icons/classic/solid'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { IconContainer } from '../sharedStyles/shared.styles'\nimport {\n FloatingFocusManager,\n useClick,\n useDismiss,\n useFloating,\n useInteractions,\n useListNavigation,\n useRole,\n} from '@floating-ui/react'\nimport { focusOutlineStyle } from '../utils/focusOutline'\n\nexport type ActionDropdownProps = {\n id?: string\n className?: string\n /** label displayed above the dropdown */\n label?: string\n /** value */\n value: ActionListItem\n /** list of items for the dropdown list */\n list: ActionListItem[]\n /** onSelect handler */\n onSelect: (action: ActionListItem) => void\n} & MarginProps\n\nexport const ActionDropdown: FC<ActionDropdownProps> = ({\n id: idProp,\n className = '',\n label,\n value,\n list,\n onSelect,\n ...marginProps\n}) => {\n const [open, setOpen] = useState(false)\n const [activeIndex, setActiveIndex] = useState<number | null>(null)\n const listRef = useRef<Array<HTMLElement | null>>([])\n\n const generatedId = useId()\n const id = idProp ?? generatedId\n const buttonId = `${id}-button`\n\n const theme = useTheme()\n\n const resolvedBgColor = resolveToThemeColor(\n value.bgColor ?? 'color.background.100',\n theme,\n )\n const resolvedTextColor = resolveToThemeColor(\n value.textColor ?? 'color.text.base',\n theme,\n )\n\n const { refs, context } = useFloating({\n open,\n onOpenChange: (nextOpen) => {\n setOpen(nextOpen)\n if (!nextOpen) setActiveIndex(null)\n },\n })\n\n const click = useClick(context)\n const dismiss = useDismiss(context)\n const role = useRole(context, { role: 'listbox' })\n const listNavigation = useListNavigation(context, {\n listRef,\n activeIndex,\n selectedIndex: list.findIndex((item) => item.value === value.value),\n onNavigate: setActiveIndex,\n loop: true,\n })\n\n const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions(\n [click, dismiss, role, listNavigation],\n )\n\n const selectOption = (option: ActionListItem) => {\n onSelect(option)\n setOpen(false)\n setActiveIndex(null)\n }\n\n const handleListKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if ((event.key === 'Enter' || event.key === ' ') && activeIndex !== null) {\n event.preventDefault()\n selectOption(list[activeIndex])\n }\n }\n\n return (\n <Container id={idProp} className={className} {...marginProps}>\n {label && (\n <Text tag=\"label\" htmlFor={buttonId} color=\"sesame\" typo=\"label\">\n {label}\n </Text>\n )}\n\n <Label\n ref={refs.setReference}\n id={buttonId}\n type=\"button\"\n aria-label={label ? undefined : 'Select an option'}\n $text={resolvedTextColor}\n $bg={resolvedBgColor}\n {...getReferenceProps()}\n >\n <SelectedOption>{value.label}</SelectedOption>\n <IconContainer\n $size={20}\n style={{\n rotate: open ? '180deg' : '0deg',\n }}\n >\n <FontAwesomeIcon icon={faChevronDown} color={resolvedTextColor} />\n </IconContainer>\n </Label>\n <OuterContainer open={open}>\n {open && (\n <FloatingFocusManager context={context} modal={false} returnFocus>\n <ListContainer\n // oxlint-disable-next-line react/react-compiler\n ref={refs.setFloating}\n {...getFloatingProps({ onKeyDown: handleListKeyDown })}\n >\n <ListItems\n options={list}\n selectedValue={value.value}\n activeIndex={activeIndex}\n listRef={listRef}\n getItemProps={getItemProps}\n onSelect={selectOption}\n />\n </ListContainer>\n </FloatingFocusManager>\n )}\n </OuterContainer>\n </Container>\n )\n}\n\ninterface ISelected {\n $text: string\n $bg: string\n}\n\nconst Label = styled.button<ISelected>(\n ({ $text, $bg }) => css`\n color: ${$text};\n background-color: ${$bg};\n position: relative;\n width: 100%;\n height: 48px;\n display: flex;\n align-items: center;\n justify-content: space-between;\n text-align: center;\n border: 0;\n border-radius: 100px;\n padding: 16px 16px 14px;\n box-sizing: border-box;\n font: inherit;\n cursor: pointer;\n user-select: none;\n ${focusOutlineStyle}\n `,\n)\n\nconst SelectedOption = styled.span`\n font-size: 14px;\n font-weight: bold;\n white-space: nowrap;\n text-overflow: ellipsis;\n`\n\nconst Container = styled(Box)`\n position: relative;\n display: block;\n width: 210px;\n height: 48px;\n text-align: center;\n border-radius: 8px;\n`\n\ninterface IOpen {\n open: boolean\n}\n\nconst OuterContainer = styled.div<IOpen>(\n ({ open }) => css`\n position: absolute;\n width: 100%;\n border-radius: 12px;\n margin-top: ${({ theme }) => theme.space[100]};\n display: ${open ? 'block' : 'none'};\n max-height: ${open ? '235px' : '48px'};\n background-color: ${({ theme }) => theme.color.surface.base[300]};\n overflow-y: ${open ? 'auto' : 'hidden'};\n z-index: 4;\n transition: all 0.2s ease-in-out;\n `,\n)\n"]}
@@ -1,4 +1,5 @@
1
- import { FC } from 'react';
1
+ import { FC, MutableRefObject } from 'react';
2
+ import type { useInteractions } from '@floating-ui/react';
2
3
  import { ColorTypes } from '../ThemeProvider/utils/colourMap';
3
4
  export type ActionListItem = {
4
5
  label: string;
@@ -6,9 +7,17 @@ export type ActionListItem = {
6
7
  bgColor?: ColorTypes;
7
8
  textColor?: ColorTypes;
8
9
  };
10
+ type Interactions = ReturnType<typeof useInteractions>;
9
11
  type Props = {
10
12
  options: ActionListItem[];
11
- selectOption: (option: ActionListItem) => void;
13
+ selectedValue: string;
14
+ activeIndex: number | null;
15
+ listRef: MutableRefObject<Array<HTMLElement | null>>;
16
+ getItemProps: Interactions['getItemProps'];
17
+ onSelect: (option: ActionListItem) => void;
12
18
  };
13
- export declare const List: FC<Props>;
19
+ export declare const ListItems: FC<Props>;
20
+ export declare const ListContainer: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, "style"> & {
21
+ style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
22
+ }> & string;
14
23
  export {};
@@ -1,27 +1,37 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import styled from 'styled-components';
3
3
  import { darken } from 'polished';
4
- export const List = ({ options, selectOption }) => (_jsx(Container, { children: options.map((option) => (_jsx(ListItem, { onClick: () => selectOption(option), children: option.label }, option.value))) }));
5
- const Container = styled.ul `
4
+ import { fontStyleMapping } from '../Text/fontMapping';
5
+ export const ListItems = ({ options, selectedValue, activeIndex, listRef, getItemProps, onSelect, }) => options.map((option, index) => (_jsx(ListItem, { ref: (node) => {
6
+ listRef.current[index] = node;
7
+ }, role: "option", "aria-selected": option.value === selectedValue, tabIndex: activeIndex === index ? 0 : -1, ...getItemProps({ onClick: () => onSelect(option) }), children: option.label }, option.value)));
8
+ export const ListContainer = styled.ul `
6
9
  padding: 0;
7
10
  margin: 0;
8
- max-height: 188px;
11
+ max-height: 192px;
12
+ list-style: none;
13
+ outline: none;
9
14
  `;
10
15
  const ListItem = styled.li `
11
- padding: 16px 24px;
16
+ padding: 14px 24px;
12
17
  text-align: left;
13
18
  overflow: hidden;
14
19
  white-space: nowrap;
15
20
  text-overflow: ellipsis;
16
21
  box-sizing: border-box;
17
- font-size: 14px;
22
+ ${fontStyleMapping['body-small']};
18
23
  cursor: pointer;
19
24
  color: ${({ theme }) => theme.color.surface.base[900]};
20
25
 
21
- &:hover {
26
+ &:hover,
27
+ &:focus-visible {
22
28
  background-color: ${({ theme }) => darken(0.1, theme.color.surface.base[300])};
23
29
  }
24
30
 
31
+ &:focus-visible {
32
+ outline: none;
33
+ }
34
+
25
35
  &:last-child {
26
36
  border-bottom: none;
27
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"List.js","sourceRoot":"","sources":["../../src/ActionDropdown/List.tsx"],"names":[],"mappings":";AACA,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAejC,MAAM,CAAC,MAAM,IAAI,GAAc,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAC5D,KAAC,SAAS,cACP,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACvB,KAAC,QAAQ,IAAoB,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,YAC7D,MAAM,CAAC,KAAK,IADA,MAAM,CAAC,KAAK,CAEhB,CACZ,CAAC,GACQ,CACb,CAAA;AAED,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAA;;;;CAI1B,CAAA;AAED,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAA;;;;;;;;;WASf,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;;;wBAG/B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAChC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;;;;;;CAM/C,CAAA","sourcesContent":["import { FC } from 'react'\nimport styled from 'styled-components'\n\nimport { darken } from 'polished'\nimport { ColorTypes } from '../ThemeProvider/utils/colourMap'\n\nexport type ActionListItem = {\n label: string\n value: string\n bgColor?: ColorTypes\n textColor?: ColorTypes\n}\n\ntype Props = {\n options: ActionListItem[]\n selectOption: (option: ActionListItem) => void\n}\n\nexport const List: FC<Props> = ({ options, selectOption }) => (\n <Container>\n {options.map((option) => (\n <ListItem key={option.value} onClick={() => selectOption(option)}>\n {option.label}\n </ListItem>\n ))}\n </Container>\n)\n\nconst Container = styled.ul`\n padding: 0;\n margin: 0;\n max-height: 188px;\n`\n\nconst ListItem = styled.li`\n padding: 16px 24px;\n text-align: left;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n box-sizing: border-box;\n font-size: 14px;\n cursor: pointer;\n color: ${({ theme }) => theme.color.surface.base[900]};\n\n &:hover {\n background-color: ${({ theme }) =>\n darken(0.1, theme.color.surface.base[300])};\n }\n\n &:last-child {\n border-bottom: none;\n }\n`\n"]}
1
+ {"version":3,"file":"List.js","sourceRoot":"","sources":["../../src/ActionDropdown/List.tsx"],"names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;;;;;;;CAU/C,CAAA","sourcesContent":["import { FC, MutableRefObject } from 'react'\nimport styled from 'styled-components'\nimport type { useInteractions } from '@floating-ui/react'\n\nimport { darken } from 'polished'\nimport { ColorTypes } from '../ThemeProvider/utils/colourMap'\nimport { fontStyleMapping } from '../Text/fontMapping'\n\nexport type ActionListItem = {\n label: string\n value: string\n bgColor?: ColorTypes\n textColor?: ColorTypes\n}\n\ntype Interactions = ReturnType<typeof useInteractions>\n\ntype Props = {\n options: ActionListItem[]\n selectedValue: string\n activeIndex: number | null\n listRef: MutableRefObject<Array<HTMLElement | null>>\n getItemProps: Interactions['getItemProps']\n onSelect: (option: ActionListItem) => void\n}\n\nexport const ListItems: FC<Props> = ({\n options,\n selectedValue,\n activeIndex,\n listRef,\n getItemProps,\n onSelect,\n}) =>\n options.map((option, index) => (\n <ListItem\n key={option.value}\n ref={(node) => {\n listRef.current[index] = node\n }}\n role=\"option\"\n aria-selected={option.value === selectedValue}\n tabIndex={activeIndex === index ? 0 : -1}\n {...getItemProps({ onClick: () => onSelect(option) })}\n >\n {option.label}\n </ListItem>\n ))\n\nexport const ListContainer = styled.ul`\n padding: 0;\n margin: 0;\n max-height: 192px;\n list-style: none;\n outline: none;\n`\n\nconst ListItem = styled.li`\n padding: 14px 24px;\n text-align: left;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n box-sizing: border-box;\n ${fontStyleMapping['body-small']};\n cursor: pointer;\n color: ${({ theme }) => theme.color.surface.base[900]};\n\n &:hover,\n &:focus-visible {\n background-color: ${({ theme }) =>\n darken(0.1, theme.color.surface.base[300])};\n }\n\n &:focus-visible {\n outline: none;\n }\n\n &:last-child {\n border-bottom: none;\n }\n`\n"]}
@@ -1 +1,3 @@
1
1
  export { ActionDropdown } from './ActionDropdown';
2
+ export type { ActionDropdownProps } from './ActionDropdown';
3
+ export type { ActionListItem } from './List';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ActionDropdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA","sourcesContent":["export { ActionDropdown } from './ActionDropdown'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ActionDropdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA","sourcesContent":["export { ActionDropdown } from './ActionDropdown'\nexport type { ActionDropdownProps } from './ActionDropdown'\nexport type { ActionListItem } from './List'\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrshmllw/smores-react",
3
- "version": "16.10.5",
3
+ "version": "16.10.7",
4
4
  "description": "Collection of React components used by Marshmallow Technology",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",