@mrshmllw/smores-react 16.11.4 → 16.12.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.
@@ -11,7 +11,28 @@ export const SearchOptions = ({ displayedList, selectedValue, highlightedIndex,
11
11
  useEffect(() => {
12
12
  itemRefs.current = displayedList.map((_, i) => itemRefs.current[i] ?? createRef());
13
13
  }, [displayedList.length]);
14
+ // Only keyboard highlights scroll the list. Scrolling to a hovered option
15
+ // moves the next one under the cursor, which then highlights and scrolls
16
+ // too, so the list runs away from the mouse.
17
+ const highlightedByMouse = useRef(false);
18
+ const highlightWithMouse = (index, option) => {
19
+ if (index === highlightedIndex)
20
+ return;
21
+ // The list's edge hit-tests to the option just past it, which is hidden
22
+ const list = resultsListRef.current;
23
+ if (list?.clientHeight &&
24
+ (option.offsetTop >= list.scrollTop + list.clientHeight ||
25
+ option.offsetTop + option.offsetHeight <= list.scrollTop)) {
26
+ return;
27
+ }
28
+ highlightedByMouse.current = true;
29
+ setHighlightedIndex(index);
30
+ };
14
31
  useEffect(() => {
32
+ if (highlightedByMouse.current) {
33
+ highlightedByMouse.current = false;
34
+ return;
35
+ }
15
36
  const focusedListItem = itemRefs?.current[highlightedIndex]?.current;
16
37
  if (highlightedIndex >= 0 && focusedListItem) {
17
38
  focusedListItem.scrollIntoView({
@@ -51,11 +72,10 @@ export const SearchOptions = ({ displayedList, selectedValue, highlightedIndex,
51
72
  // oxlint-disable-next-line react/react-compiler
52
73
  displayedList.map((el, i) => {
53
74
  const isSelected = selectedValue === el.label || selectedValue === el.value;
54
- return (_jsxs(ListButton, { id: getOptionId(i), role: "option", "aria-selected": highlightedIndex === i, ref: itemRefs.current[i], onClick: () => onSelect(el), $isSelected: isSelected, $showBg: highlightedIndex === i, onMouseEnter: () => {
55
- setHighlightedIndex(i);
56
- }, onFocus: () => {
57
- setHighlightedIndex(i);
58
- }, children: [el.label, isSelected && (_jsx(Icon, { render: "tick", size: 16, color: "color.surface.brand.300" }))] }, el.label + '_list_item'));
75
+ return (_jsxs(ListButton, { id: getOptionId(i), role: "option", "aria-selected": highlightedIndex === i, ref: itemRefs.current[i], onClick: () => onSelect(el), $isSelected: isSelected, $showBg: highlightedIndex === i,
76
+ // Mouse move, not enter, so an option scrolling under a
77
+ // still cursor doesn't take the highlight
78
+ onMouseMove: (event) => highlightWithMouse(i, event.currentTarget), children: [el.label, isSelected && (_jsx(Icon, { render: "tick", size: 16, color: "color.surface.brand.300" }))] }, el.label + '_list_item'));
59
79
  })) : (_jsx(EmptyResults, { onNotFound: onNotFound, onMessageChange: onEmptyMessageChange, searchTerm: searchTerm, notFoundComponent: notFoundComponent })) }) }) }));
60
80
  };
61
81
  const StyledResultsContainer = styled.div `
@@ -1 +1 @@
1
- {"version":3,"file":"SearchOptions.js","sourceRoot":"","sources":["../../../src/SearchInput/components/SearchOptions.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,SAAS,EACT,SAAS,EACT,eAAe,EACf,MAAM,GACP,MAAM,OAAO,CAAA;AACd,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AA+BzD,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,EACpD,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,UAAU,EACV,iBAAiB,GAClB,EAAE,EAAE;IACH,MAAM,QAAQ,GAAG,MAAM,CAAoC,EAAE,CAAC,CAAA;IAC9D,MAAM,cAAc,GAAG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AM;;;;;;;;;MASxD,gBAAgB,CAAC,cAAc,CAAC;aACzB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;;;CAGhD,CAAA;AAED,MAAM,UAAU,GAAG,MAAM,CAAC,EAAE,CAA4C;;;;;;;;;;;;IAYpE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChB,OAAO;IACP,GAAG,CAAA;0BACmB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;KAC/D;;IAED,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CACpB,WAAW;IACX,GAAG,CAAA;0BACmB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;KACjE;CACJ,CAAA;AAED,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;CAE1C,CAAA","sourcesContent":["import {\n FC,\n ReactNode,\n RefObject,\n createRef,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport styled, { css } from 'styled-components'\nimport { TransientProps } from '../../utils/utilTypes'\nimport { Box } from '../../Box'\nimport { Icon } from '../../Icon'\nimport { EmptyResults } from './EmptyResults'\nimport { fontStyleMapping } from '../../Text/fontMapping'\n\ntype Option = {\n label: string\n value: string\n}\n\nexport type SearchKeyEvent = {\n key: string\n preventDefault: () => void\n stopPropagation: () => void\n}\n\ntype SearchOptionsProps = {\n displayedList: Array<Option>\n selectedValue: string | null\n highlightedIndex: number\n setHighlightedIndex: (arg: number) => void\n onSelect: (option: Option) => void\n onKeyDown: (e: SearchKeyEvent) => void\n listboxId: string\n listboxLabel: string\n getOptionId: (index: number) => string\n positionRelative: boolean\n resultsBorder: boolean\n onNotFound?: (searchTerm: string) => void\n onEmptyMessageChange: (message: string) => void\n searchTerm: string\n notFoundComponent?: ReactNode\n}\n\nexport const SearchOptions: FC<SearchOptionsProps> = ({\n displayedList,\n selectedValue,\n highlightedIndex,\n setHighlightedIndex,\n onSelect,\n onKeyDown,\n listboxId,\n listboxLabel,\n getOptionId,\n positionRelative,\n resultsBorder,\n onNotFound,\n onEmptyMessageChange,\n searchTerm,\n notFoundComponent,\n}) => {\n const itemRefs = useRef<RefObject<HTMLLIElement | null>[]>([])\n const resultsListRef = useRef<HTMLUListElement>(null)\n\n useEffect(() => {\n itemRefs.current = displayedList.map(\n (_, i) => itemRefs.current[i] ?? createRef<HTMLLIElement>(),\n )\n }, [displayedList.length])\n\n useEffect(() => {\n const focusedListItem = itemRefs?.current[highlightedIndex]?.current\n if (highlightedIndex >= 0 && focusedListItem) {\n focusedListItem.scrollIntoView({\n block: 'nearest',\n inline: 'start',\n })\n }\n }, [highlightedIndex])\n\n // Only reset the scroll when the search term changes, not when the list\n // opens, so the selected option stays centred\n const scrollResetForSearchTerm = useRef(searchTerm)\n useEffect(() => {\n if (\n resultsListRef.current &&\n scrollResetForSearchTerm.current !== searchTerm\n ) {\n resultsListRef.current.scrollTop = 0\n }\n scrollResetForSearchTerm.current = searchTerm\n setHighlightedIndex(-1)\n }, [searchTerm, setHighlightedIndex])\n\n // When the list opens, centre the selected option in it. This sets the\n // list's own scrollTop so the page doesn't scroll.\n const hasScrolledToSelected = useRef(false)\n useLayoutEffect(() => {\n if (hasScrolledToSelected.current) return\n hasScrolledToSelected.current = true\n\n const list = resultsListRef.current\n const selectedIndex = displayedList.findIndex(\n (el) => selectedValue === el.label || selectedValue === el.value,\n )\n const selectedItem = list?.children[selectedIndex] as\n HTMLElement | undefined\n if (list && selectedItem) {\n list.scrollTop =\n selectedItem.offsetTop -\n (list.clientHeight - selectedItem.offsetHeight) / 2\n }\n }, [displayedList, selectedValue])\n\n return (\n <BoxWithPositionRelative>\n <StyledResultsContainer $positionRelative={positionRelative}>\n <ResultsList\n ref={resultsListRef}\n id={listboxId}\n role={displayedList.length ? 'listbox' : undefined}\n aria-label={displayedList.length ? listboxLabel : undefined}\n $resultsBorder={resultsBorder}\n onKeyDown={onKeyDown}\n >\n {displayedList.length ? (\n // oxlint-disable-next-line react/react-compiler\n displayedList.map((el, i) => {\n const isSelected =\n selectedValue === el.label || selectedValue === el.value\n\n return (\n <ListButton\n key={el.label + '_list_item'}\n id={getOptionId(i)}\n role=\"option\"\n aria-selected={highlightedIndex === i}\n ref={itemRefs.current[i]}\n onClick={() => onSelect(el)}\n $isSelected={isSelected}\n $showBg={highlightedIndex === i}\n onMouseEnter={() => {\n setHighlightedIndex(i)\n }}\n onFocus={() => {\n setHighlightedIndex(i)\n }}\n >\n {el.label}\n {isSelected && (\n <Icon\n render=\"tick\"\n size={16}\n color=\"color.surface.brand.300\"\n />\n )}\n </ListButton>\n )\n })\n ) : (\n <EmptyResults\n onNotFound={onNotFound}\n onMessageChange={onEmptyMessageChange}\n searchTerm={searchTerm}\n notFoundComponent={notFoundComponent}\n />\n )}\n </ResultsList>\n </StyledResultsContainer>\n </BoxWithPositionRelative>\n )\n}\n\nconst StyledResultsContainer = styled.div<\n TransientProps<Pick<SearchOptionsProps, 'positionRelative'>>\n>`\n box-sizing: border-box;\n overflow: hidden;\n margin: -16px;\n padding: ${({ theme }) => theme.space[200]};\n ${({ $positionRelative }) => !$positionRelative && 'position: absolute;'}\n width: calc(100% + 32px);\n left: 0px;\n top: -8px;\n\n ul {\n box-sizing: border-box;\n max-height: 194px;\n }\n`\n\nconst ResultsList = styled.ul<\n TransientProps<Pick<SearchOptionsProps, 'resultsBorder'>>\n>`\n position: relative;\n list-style: none;\n overflow-y: auto;\n padding: 0;\n margin: 0;\n background-color: ${({ theme }) => theme.color.background['000']};\n border-radius: 12px;\n margin-top: 14px;\n z-index: 1000;\n border: 1px solid ${({ theme }) => theme.color.border.subtle};\n box-shadow:\n 0px 10px 18px rgba(18, 18, 23, 0.03),\n 0px 5px 8px rgba(18, 18, 23, 0.04),\n 0px 2px 4px rgba(18, 18, 23, 0.04);\n\n li {\n padding: 14px;\n box-sizing: border-box;\n ${fontStyleMapping['body-regular']};\n color: ${({ theme }) => theme.color.text.base};\n cursor: pointer;\n }\n`\n\nconst ListButton = styled.li<{ $isSelected: boolean; $showBg: boolean }>`\n display: flex;\n justify-content: space-between;\n align-items: center;\n\n &:focus {\n outline: none;\n }\n &:focus-visible {\n outline: none;\n }\n\n ${({ $showBg }) =>\n $showBg &&\n css`\n background-color: ${({ theme }) => theme.color.background[200]};\n `}\n\n ${({ $isSelected }) =>\n $isSelected &&\n css`\n background-color: ${({ theme }) => theme.color.surface.base[300]};\n `}\n`\n\nconst BoxWithPositionRelative = styled(Box)`\n position: relative;\n`\n"]}
1
+ {"version":3,"file":"SearchOptions.js","sourceRoot":"","sources":["../../../src/SearchInput/components/SearchOptions.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,SAAS,EACT,SAAS,EACT,eAAe,EACf,MAAM,GACP,MAAM,OAAO,CAAA;AACd,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AA+BzD,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,EACpD,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,UAAU,EACV,iBAAiB,GAClB,EAAE,EAAE;IACH,MAAM,QAAQ,GAAG,MAAM,CAAoC,EAAE,CAAC,CAAA;IAC9D,MAAM,cAAc,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAA;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ED,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;CAE1C,CAAA","sourcesContent":["import {\n FC,\n ReactNode,\n RefObject,\n createRef,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport styled, { css } from 'styled-components'\nimport { TransientProps } from '../../utils/utilTypes'\nimport { Box } from '../../Box'\nimport { Icon } from '../../Icon'\nimport { EmptyResults } from './EmptyResults'\nimport { fontStyleMapping } from '../../Text/fontMapping'\n\ntype Option = {\n label: string\n value: string\n}\n\nexport type SearchKeyEvent = {\n key: string\n preventDefault: () => void\n stopPropagation: () => void\n}\n\ntype SearchOptionsProps = {\n displayedList: Array<Option>\n selectedValue: string | null\n highlightedIndex: number\n setHighlightedIndex: (arg: number) => void\n onSelect: (option: Option) => void\n onKeyDown: (e: SearchKeyEvent) => void\n listboxId: string\n listboxLabel: string\n getOptionId: (index: number) => string\n positionRelative: boolean\n resultsBorder: boolean\n onNotFound?: (searchTerm: string) => void\n onEmptyMessageChange: (message: string) => void\n searchTerm: string\n notFoundComponent?: ReactNode\n}\n\nexport const SearchOptions: FC<SearchOptionsProps> = ({\n displayedList,\n selectedValue,\n highlightedIndex,\n setHighlightedIndex,\n onSelect,\n onKeyDown,\n listboxId,\n listboxLabel,\n getOptionId,\n positionRelative,\n resultsBorder,\n onNotFound,\n onEmptyMessageChange,\n searchTerm,\n notFoundComponent,\n}) => {\n const itemRefs = useRef<RefObject<HTMLLIElement | null>[]>([])\n const resultsListRef = useRef<HTMLUListElement>(null)\n\n useEffect(() => {\n itemRefs.current = displayedList.map(\n (_, i) => itemRefs.current[i] ?? createRef<HTMLLIElement>(),\n )\n }, [displayedList.length])\n\n // Only keyboard highlights scroll the list. Scrolling to a hovered option\n // moves the next one under the cursor, which then highlights and scrolls\n // too, so the list runs away from the mouse.\n const highlightedByMouse = useRef(false)\n const highlightWithMouse = (index: number, option: HTMLLIElement) => {\n if (index === highlightedIndex) return\n // The list's edge hit-tests to the option just past it, which is hidden\n const list = resultsListRef.current\n if (\n list?.clientHeight &&\n (option.offsetTop >= list.scrollTop + list.clientHeight ||\n option.offsetTop + option.offsetHeight <= list.scrollTop)\n ) {\n return\n }\n highlightedByMouse.current = true\n setHighlightedIndex(index)\n }\n\n useEffect(() => {\n if (highlightedByMouse.current) {\n highlightedByMouse.current = false\n return\n }\n const focusedListItem = itemRefs?.current[highlightedIndex]?.current\n if (highlightedIndex >= 0 && focusedListItem) {\n focusedListItem.scrollIntoView({\n block: 'nearest',\n inline: 'start',\n })\n }\n }, [highlightedIndex])\n\n // Only reset the scroll when the search term changes, not when the list\n // opens, so the selected option stays centred\n const scrollResetForSearchTerm = useRef(searchTerm)\n useEffect(() => {\n if (\n resultsListRef.current &&\n scrollResetForSearchTerm.current !== searchTerm\n ) {\n resultsListRef.current.scrollTop = 0\n }\n scrollResetForSearchTerm.current = searchTerm\n setHighlightedIndex(-1)\n }, [searchTerm, setHighlightedIndex])\n\n // When the list opens, centre the selected option in it. This sets the\n // list's own scrollTop so the page doesn't scroll.\n const hasScrolledToSelected = useRef(false)\n useLayoutEffect(() => {\n if (hasScrolledToSelected.current) return\n hasScrolledToSelected.current = true\n\n const list = resultsListRef.current\n const selectedIndex = displayedList.findIndex(\n (el) => selectedValue === el.label || selectedValue === el.value,\n )\n const selectedItem = list?.children[selectedIndex] as\n HTMLElement | undefined\n if (list && selectedItem) {\n list.scrollTop =\n selectedItem.offsetTop -\n (list.clientHeight - selectedItem.offsetHeight) / 2\n }\n }, [displayedList, selectedValue])\n\n return (\n <BoxWithPositionRelative>\n <StyledResultsContainer $positionRelative={positionRelative}>\n <ResultsList\n ref={resultsListRef}\n id={listboxId}\n role={displayedList.length ? 'listbox' : undefined}\n aria-label={displayedList.length ? listboxLabel : undefined}\n $resultsBorder={resultsBorder}\n onKeyDown={onKeyDown}\n >\n {displayedList.length ? (\n // oxlint-disable-next-line react/react-compiler\n displayedList.map((el, i) => {\n const isSelected =\n selectedValue === el.label || selectedValue === el.value\n\n return (\n <ListButton\n key={el.label + '_list_item'}\n id={getOptionId(i)}\n role=\"option\"\n aria-selected={highlightedIndex === i}\n ref={itemRefs.current[i]}\n onClick={() => onSelect(el)}\n $isSelected={isSelected}\n $showBg={highlightedIndex === i}\n // Mouse move, not enter, so an option scrolling under a\n // still cursor doesn't take the highlight\n onMouseMove={(event) =>\n highlightWithMouse(i, event.currentTarget)\n }\n >\n {el.label}\n {isSelected && (\n <Icon\n render=\"tick\"\n size={16}\n color=\"color.surface.brand.300\"\n />\n )}\n </ListButton>\n )\n })\n ) : (\n <EmptyResults\n onNotFound={onNotFound}\n onMessageChange={onEmptyMessageChange}\n searchTerm={searchTerm}\n notFoundComponent={notFoundComponent}\n />\n )}\n </ResultsList>\n </StyledResultsContainer>\n </BoxWithPositionRelative>\n )\n}\n\nconst StyledResultsContainer = styled.div<\n TransientProps<Pick<SearchOptionsProps, 'positionRelative'>>\n>`\n box-sizing: border-box;\n overflow: hidden;\n margin: -16px;\n padding: ${({ theme }) => theme.space[200]};\n ${({ $positionRelative }) => !$positionRelative && 'position: absolute;'}\n width: calc(100% + 32px);\n left: 0px;\n top: -8px;\n\n ul {\n box-sizing: border-box;\n max-height: 194px;\n }\n`\n\nconst ResultsList = styled.ul<\n TransientProps<Pick<SearchOptionsProps, 'resultsBorder'>>\n>`\n position: relative;\n list-style: none;\n overflow-y: auto;\n padding: 0;\n margin: 0;\n background-color: ${({ theme }) => theme.color.background['000']};\n border-radius: 12px;\n margin-top: 14px;\n z-index: 1000;\n border: 1px solid ${({ theme }) => theme.color.border.subtle};\n box-shadow:\n 0px 10px 18px rgba(18, 18, 23, 0.03),\n 0px 5px 8px rgba(18, 18, 23, 0.04),\n 0px 2px 4px rgba(18, 18, 23, 0.04);\n\n li {\n padding: 14px;\n box-sizing: border-box;\n ${fontStyleMapping['body-regular']};\n color: ${({ theme }) => theme.color.text.base};\n cursor: pointer;\n }\n`\n\nconst ListButton = styled.li<{ $isSelected: boolean; $showBg: boolean }>`\n display: flex;\n justify-content: space-between;\n align-items: center;\n\n &:focus {\n outline: none;\n }\n &:focus-visible {\n outline: none;\n }\n\n ${({ $showBg }) =>\n $showBg &&\n css`\n background-color: ${({ theme }) => theme.color.background[200]};\n `}\n\n ${({ $isSelected }) =>\n $isSelected &&\n css`\n background-color: ${({ theme }) => theme.color.surface.base[300]};\n `}\n`\n\nconst BoxWithPositionRelative = styled(Box)`\n position: relative;\n`\n"]}
@@ -12,7 +12,17 @@ type BaseProps = {
12
12
  disabled?: boolean;
13
13
  maxLength?: number;
14
14
  onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void;
15
+ /**
16
+ * Number of lines the textarea shows before it has any content to grow with. Defaults to 4.
17
+ * A `height` set in CSS on the textarea becomes the starting height instead.
18
+ */
15
19
  rows?: number;
20
+ /**
21
+ * The most lines the textarea grows to as the content gets longer. Past this it scrolls.
22
+ * Defaults to 8. A value lower than `rows` is treated as `rows`. A taller
23
+ * `height` set in CSS on the textarea raises the cap to match it.
24
+ */
25
+ maxRows?: number;
16
26
  fallbackStyle?: boolean;
17
27
  } & CommonFieldProps & MarginProps;
18
28
  type TruncateProps = {
@@ -1,33 +1,137 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
2
+ import { forwardRef, useCallback, useLayoutEffect, useRef, } from 'react';
3
3
  import styled from 'styled-components';
4
+ import { useMergeRefs } from '@floating-ui/react';
4
5
  import { Field } from '../fields/Field';
5
6
  import { useUniqueId } from '../utils/id';
6
7
  import { getFieldAria } from '../fields/fieldAria';
7
8
  import { fieldDisabledStyle, fieldFocusAttrs, fieldFocusRing, fieldHoverBorderColor, } from '../fields/components/fieldStyles';
8
- export const Textarea = forwardRef(function Textarea({ id: idProp, name, value, onChange, onInputChange, resize = 'none', error = false, placeholder, disabled = false, maxLength, onBlur, rows = 4, fallbackStyle, ...fieldProps }, ref) {
9
+ const LINE_HEIGHT = 20;
10
+ const PADDING = 12;
11
+ const BORDER = 2;
12
+ // Padding and border (top and bottom) around the lines of text
13
+ const CHROME_HEIGHT = 2 * (PADDING + BORDER);
14
+ const DEFAULT_ROWS = 4;
15
+ const DEFAULT_MAX_ROWS = 8;
16
+ export const Textarea = forwardRef(function Textarea({ id: idProp, name, value, onChange, onInputChange, resize = 'none', error = false, placeholder, disabled = false, maxLength, onBlur, rows = DEFAULT_ROWS, maxRows = DEFAULT_MAX_ROWS, fallbackStyle, ...fieldProps }, ref) {
9
17
  const id = useUniqueId(idProp);
18
+ const innerRef = useRef(null);
19
+ const mergedRef = useMergeRefs([ref, innerRef]);
20
+ // Set once the user drags the resize handle. From then on their size wins
21
+ // and the height is no longer fitted to the content.
22
+ const userSizedRef = useRef(false);
23
+ const pointerDownRef = useRef(false);
24
+ // The height we last wrote, to tell our own size changes from the user's
25
+ const lastFitHeightRef = useRef(null);
10
26
  const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {
11
27
  ...fieldProps,
12
28
  error,
13
29
  });
14
- return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, assistiveTextId: assistiveTextId, errorMsgId: errorMsgId, children: _jsx(StyledTextArea, { ref: ref, $error: error, id: id, name: name, disabled: disabled, $resize: resize, $fallbackStyle: fallbackStyle, placeholder: placeholder, value: value, onChange: (e) => {
30
+ const fitHeightToContent = useCallback(() => {
31
+ const el = innerRef.current;
32
+ if (!el || userSizedRef.current)
33
+ return;
34
+ // Measure from the height the stylesheet gives the textarea, which is a
35
+ // height set in CSS if there is one, otherwise the `rows` height. Hide the
36
+ // scrollbar so it doesn't take up width and change how the text wraps.
37
+ el.style.overflowY = 'hidden';
38
+ el.style.height = '';
39
+ const minHeight = Math.max(el.offsetHeight, rows * LINE_HEIGHT + CHROME_HEIGHT);
40
+ const maxHeight = Math.max(Math.max(rows, maxRows) * LINE_HEIGHT + CHROME_HEIGHT, minHeight);
41
+ // scrollHeight is never less than the visible height, and includes the
42
+ // padding but not the border.
43
+ const contentHeight = el.scrollHeight + 2 * BORDER;
44
+ const height = Math.min(Math.max(contentHeight, minHeight), maxHeight);
45
+ lastFitHeightRef.current = height;
46
+ el.style.height = `${height}px`;
47
+ // A box the user has dragged smaller than its content still needs to scroll.
48
+ el.style.overflowY =
49
+ contentHeight > maxHeight || resize === 'both' ? 'auto' : 'hidden';
50
+ }, [rows, maxRows, resize]);
51
+ // Dragging the resize handle is only possible with resize="both". Track
52
+ // whether a pointer is down so the observer below can tell a drag from the
53
+ // container changing width. This is declared before the effect that fits the
54
+ // height, so that leaving "both" forgets the dragged size first and the fit
55
+ // that follows (its callback changes with `resize`) is not skipped.
56
+ useLayoutEffect(() => {
57
+ const el = innerRef.current;
58
+ if (!el || resize !== 'both') {
59
+ userSizedRef.current = false;
60
+ // Drop the width a drag left behind
61
+ if (el)
62
+ el.style.width = '';
63
+ return;
64
+ }
65
+ const onDown = () => {
66
+ pointerDownRef.current = true;
67
+ };
68
+ const onUp = () => {
69
+ pointerDownRef.current = false;
70
+ };
71
+ el.addEventListener('pointerdown', onDown);
72
+ // The pointer can be released outside the textarea
73
+ document.addEventListener('pointerup', onUp);
74
+ document.addEventListener('pointercancel', onUp);
75
+ return () => {
76
+ pointerDownRef.current = false;
77
+ el.removeEventListener('pointerdown', onDown);
78
+ document.removeEventListener('pointerup', onUp);
79
+ document.removeEventListener('pointercancel', onUp);
80
+ };
81
+ }, [resize]);
82
+ // Runs for typing and for the value being reset from outside.
83
+ useLayoutEffect(() => {
84
+ fitHeightToContent();
85
+ }, [fitHeightToContent, value]);
86
+ // A change in width rewraps the text, so the height is fitted again. Height
87
+ // changes are ignored so that resizing the box ourselves doesn't loop. A size
88
+ // we didn't write, while the pointer is down, is the user dragging the resize
89
+ // handle, so fitting stops for good.
90
+ useLayoutEffect(() => {
91
+ const el = innerRef.current;
92
+ if (!el || typeof ResizeObserver === 'undefined')
93
+ return;
94
+ let width = el.offsetWidth;
95
+ let frame = 0;
96
+ const observer = new ResizeObserver(() => {
97
+ if (pointerDownRef.current &&
98
+ (el.offsetHeight !== lastFitHeightRef.current ||
99
+ el.offsetWidth !== width)) {
100
+ userSizedRef.current = true;
101
+ cancelAnimationFrame(frame);
102
+ width = el.offsetWidth;
103
+ return;
104
+ }
105
+ if (el.offsetWidth === width)
106
+ return;
107
+ width = el.offsetWidth;
108
+ cancelAnimationFrame(frame);
109
+ frame = requestAnimationFrame(fitHeightToContent);
110
+ });
111
+ observer.observe(el);
112
+ return () => {
113
+ observer.disconnect();
114
+ cancelAnimationFrame(frame);
115
+ };
116
+ }, [fitHeightToContent]);
117
+ return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, assistiveTextId: assistiveTextId, errorMsgId: errorMsgId, children: _jsx(StyledTextArea, { ref: mergedRef, $error: error, id: id, name: name, disabled: disabled, $resize: resize, $fallbackStyle: fallbackStyle, placeholder: placeholder, value: value, onChange: (e) => {
15
118
  onChange?.(e.currentTarget.value);
16
119
  onInputChange?.(e);
17
120
  }, maxLength: maxLength, onBlur: onBlur, rows: rows, ...controlAria }) }));
18
121
  });
19
122
  const StyledTextArea = styled.textarea.attrs(fieldFocusAttrs) `
123
+ display: block;
20
124
  font-size: 16px;
21
125
  font: inherit;
22
- line-height: 20px;
126
+ line-height: ${LINE_HEIGHT}px;
23
127
  background: ${({ $fallbackStyle, theme }) => $fallbackStyle
24
128
  ? theme.color.surface.base[300]
25
129
  : theme.color.background['000']};
26
- border: 2px solid ${({ theme }) => theme.color.border.subtle};
130
+ border: ${BORDER}px solid ${({ theme }) => theme.color.border.subtle};
27
131
  box-sizing: border-box;
28
132
  border-radius: 12px;
29
133
  width: 100%;
30
- padding: 12px;
134
+ padding: ${PADDING}px;
31
135
  color: ${({ theme }) => theme.color.text.base};
32
136
  resize: ${({ $resize }) => $resize};
33
137
  cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'text')};
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../src/Textarea/Textarea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAuC,UAAU,EAAE,MAAM,OAAO,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AAE,CACpC,MAAM;IACJ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ;;;IAGjC,cAAc;IACd,kBAAkB;;;aAGT,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;;CAElD,CAAA","sourcesContent":["import { FocusEvent, FormEvent, ForwardedRef, forwardRef } from 'react'\nimport styled from 'styled-components'\n\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport {\n fieldDisabledStyle,\n fieldFocusAttrs,\n fieldFocusRing,\n fieldHoverBorderColor,\n} from '../fields/components/fieldStyles'\nimport { MarginProps } from '../utils/space'\n\ntype BaseProps = {\n id?: string\n placeholder?: string\n name?: string\n value: string\n error?: boolean\n errorMsg?: string\n resize?: 'none' | 'both'\n disabled?: boolean\n maxLength?: number\n onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void\n rows?: number\n fallbackStyle?: boolean\n} & CommonFieldProps &\n MarginProps\n\ntype TruncateProps =\n | {\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n | {\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n\nexport type TextareaProps = BaseProps & TruncateProps\n\nexport const Textarea = forwardRef(function Textarea(\n {\n id: idProp,\n name,\n value,\n onChange,\n onInputChange,\n resize = 'none',\n error = false,\n placeholder,\n disabled = false,\n maxLength,\n onBlur,\n rows = 4,\n fallbackStyle,\n ...fieldProps\n }: TextareaProps,\n ref: ForwardedRef<HTMLTextAreaElement>,\n) {\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <StyledTextArea\n ref={ref}\n $error={error}\n id={id}\n name={name}\n disabled={disabled}\n $resize={resize}\n $fallbackStyle={fallbackStyle}\n placeholder={placeholder}\n value={value}\n onChange={(e: FormEvent<HTMLTextAreaElement>) => {\n onChange?.(e.currentTarget.value)\n onInputChange?.(e)\n }}\n maxLength={maxLength}\n onBlur={onBlur}\n rows={rows}\n {...controlAria}\n />\n </Field>\n )\n})\n\ninterface TextArea {\n $resize: 'none' | 'both'\n disabled: boolean\n $error: boolean\n $fallbackStyle?: boolean\n}\n\nconst StyledTextArea = styled.textarea.attrs(fieldFocusAttrs)<TextArea>`\n font-size: 16px;\n font: inherit;\n line-height: 20px;\n background: ${({ $fallbackStyle, theme }) =>\n $fallbackStyle\n ? theme.color.surface.base[300]\n : theme.color.background['000']};\n border: 2px solid ${({ theme }) => theme.color.border.subtle};\n box-sizing: border-box;\n border-radius: 12px;\n width: 100%;\n padding: 12px;\n color: ${({ theme }) => theme.color.text.base};\n resize: ${({ $resize }) => $resize};\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'text')};\n border-color: ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};\n outline: none;\n\n &:hover:not(:disabled):not(:focus) {\n border-color: ${({ $error, theme }) => fieldHoverBorderColor(theme, $error)};\n }\n\n &:focus {\n border-color: ${({ $error, theme }) =>\n $error\n ? theme.color.feedback.negative[200]\n : theme.color.border.contrast};\n }\n\n ${fieldFocusRing}\n ${fieldDisabledStyle}\n\n &::placeholder {\n color: ${({ theme }) => theme.color.text.subtle};\n }\n`\n"]}
1
+ {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../src/Textarea/Textarea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,UAAU,EACV,WAAW,EACX,eAAe,EACf,MAAM,GACP,MAAM,OAAO,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C,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;kBAC/C,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CACpC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM;;;;oBAIvD,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC;;;;oBAI3D,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CACpC,MAAM;IACJ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ;;;IAGjC,cAAc;IACd,kBAAkB;;;aAGT,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;;CAElD,CAAA","sourcesContent":["import {\n FocusEvent,\n FormEvent,\n ForwardedRef,\n forwardRef,\n useCallback,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport styled from 'styled-components'\nimport { useMergeRefs } from '@floating-ui/react'\n\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport {\n fieldDisabledStyle,\n fieldFocusAttrs,\n fieldFocusRing,\n fieldHoverBorderColor,\n} from '../fields/components/fieldStyles'\nimport { MarginProps } from '../utils/space'\n\ntype BaseProps = {\n id?: string\n placeholder?: string\n name?: string\n value: string\n error?: boolean\n errorMsg?: string\n resize?: 'none' | 'both'\n disabled?: boolean\n maxLength?: number\n onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void\n /**\n * Number of lines the textarea shows before it has any content to grow with. Defaults to 4.\n * A `height` set in CSS on the textarea becomes the starting height instead.\n */\n rows?: number\n /**\n * The most lines the textarea grows to as the content gets longer. Past this it scrolls.\n * Defaults to 8. A value lower than `rows` is treated as `rows`. A taller\n * `height` set in CSS on the textarea raises the cap to match it.\n */\n maxRows?: number\n fallbackStyle?: boolean\n} & CommonFieldProps &\n MarginProps\n\ntype TruncateProps =\n | {\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n | {\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n\nexport type TextareaProps = BaseProps & TruncateProps\n\nconst LINE_HEIGHT = 20\nconst PADDING = 12\nconst BORDER = 2\n// Padding and border (top and bottom) around the lines of text\nconst CHROME_HEIGHT = 2 * (PADDING + BORDER)\nconst DEFAULT_ROWS = 4\nconst DEFAULT_MAX_ROWS = 8\n\nexport const Textarea = forwardRef(function Textarea(\n {\n id: idProp,\n name,\n value,\n onChange,\n onInputChange,\n resize = 'none',\n error = false,\n placeholder,\n disabled = false,\n maxLength,\n onBlur,\n rows = DEFAULT_ROWS,\n maxRows = DEFAULT_MAX_ROWS,\n fallbackStyle,\n ...fieldProps\n }: TextareaProps,\n ref: ForwardedRef<HTMLTextAreaElement>,\n) {\n const id = useUniqueId(idProp)\n const innerRef = useRef<HTMLTextAreaElement | null>(null)\n const mergedRef = useMergeRefs([ref, innerRef])\n // Set once the user drags the resize handle. From then on their size wins\n // and the height is no longer fitted to the content.\n const userSizedRef = useRef(false)\n const pointerDownRef = useRef(false)\n // The height we last wrote, to tell our own size changes from the user's\n const lastFitHeightRef = useRef<number | null>(null)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n\n const fitHeightToContent = useCallback(() => {\n const el = innerRef.current\n if (!el || userSizedRef.current) return\n\n // Measure from the height the stylesheet gives the textarea, which is a\n // height set in CSS if there is one, otherwise the `rows` height. Hide the\n // scrollbar so it doesn't take up width and change how the text wraps.\n el.style.overflowY = 'hidden'\n el.style.height = ''\n const minHeight = Math.max(\n el.offsetHeight,\n rows * LINE_HEIGHT + CHROME_HEIGHT,\n )\n const maxHeight = Math.max(\n Math.max(rows, maxRows) * LINE_HEIGHT + CHROME_HEIGHT,\n minHeight,\n )\n // scrollHeight is never less than the visible height, and includes the\n // padding but not the border.\n const contentHeight = el.scrollHeight + 2 * BORDER\n\n const height = Math.min(Math.max(contentHeight, minHeight), maxHeight)\n lastFitHeightRef.current = height\n el.style.height = `${height}px`\n // A box the user has dragged smaller than its content still needs to scroll.\n el.style.overflowY =\n contentHeight > maxHeight || resize === 'both' ? 'auto' : 'hidden'\n }, [rows, maxRows, resize])\n\n // Dragging the resize handle is only possible with resize=\"both\". Track\n // whether a pointer is down so the observer below can tell a drag from the\n // container changing width. This is declared before the effect that fits the\n // height, so that leaving \"both\" forgets the dragged size first and the fit\n // that follows (its callback changes with `resize`) is not skipped.\n useLayoutEffect(() => {\n const el = innerRef.current\n if (!el || resize !== 'both') {\n userSizedRef.current = false\n // Drop the width a drag left behind\n if (el) el.style.width = ''\n return\n }\n\n const onDown = () => {\n pointerDownRef.current = true\n }\n const onUp = () => {\n pointerDownRef.current = false\n }\n el.addEventListener('pointerdown', onDown)\n // The pointer can be released outside the textarea\n document.addEventListener('pointerup', onUp)\n document.addEventListener('pointercancel', onUp)\n return () => {\n pointerDownRef.current = false\n el.removeEventListener('pointerdown', onDown)\n document.removeEventListener('pointerup', onUp)\n document.removeEventListener('pointercancel', onUp)\n }\n }, [resize])\n\n // Runs for typing and for the value being reset from outside.\n useLayoutEffect(() => {\n fitHeightToContent()\n }, [fitHeightToContent, value])\n\n // A change in width rewraps the text, so the height is fitted again. Height\n // changes are ignored so that resizing the box ourselves doesn't loop. A size\n // we didn't write, while the pointer is down, is the user dragging the resize\n // handle, so fitting stops for good.\n useLayoutEffect(() => {\n const el = innerRef.current\n if (!el || typeof ResizeObserver === 'undefined') return\n\n let width = el.offsetWidth\n let frame = 0\n const observer = new ResizeObserver(() => {\n if (\n pointerDownRef.current &&\n (el.offsetHeight !== lastFitHeightRef.current ||\n el.offsetWidth !== width)\n ) {\n userSizedRef.current = true\n cancelAnimationFrame(frame)\n width = el.offsetWidth\n return\n }\n if (el.offsetWidth === width) return\n width = el.offsetWidth\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(fitHeightToContent)\n })\n observer.observe(el)\n return () => {\n observer.disconnect()\n cancelAnimationFrame(frame)\n }\n }, [fitHeightToContent])\n\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <StyledTextArea\n ref={mergedRef}\n $error={error}\n id={id}\n name={name}\n disabled={disabled}\n $resize={resize}\n $fallbackStyle={fallbackStyle}\n placeholder={placeholder}\n value={value}\n onChange={(e: FormEvent<HTMLTextAreaElement>) => {\n onChange?.(e.currentTarget.value)\n onInputChange?.(e)\n }}\n maxLength={maxLength}\n onBlur={onBlur}\n rows={rows}\n {...controlAria}\n />\n </Field>\n )\n})\n\ninterface TextArea {\n $resize: 'none' | 'both'\n disabled: boolean\n $error: boolean\n $fallbackStyle?: boolean\n}\n\nconst StyledTextArea = styled.textarea.attrs(fieldFocusAttrs)<TextArea>`\n display: block;\n font-size: 16px;\n font: inherit;\n line-height: ${LINE_HEIGHT}px;\n background: ${({ $fallbackStyle, theme }) =>\n $fallbackStyle\n ? theme.color.surface.base[300]\n : theme.color.background['000']};\n border: ${BORDER}px solid ${({ theme }) => theme.color.border.subtle};\n box-sizing: border-box;\n border-radius: 12px;\n width: 100%;\n padding: ${PADDING}px;\n color: ${({ theme }) => theme.color.text.base};\n resize: ${({ $resize }) => $resize};\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'text')};\n border-color: ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};\n outline: none;\n\n &:hover:not(:disabled):not(:focus) {\n border-color: ${({ $error, theme }) => fieldHoverBorderColor(theme, $error)};\n }\n\n &:focus {\n border-color: ${({ $error, theme }) =>\n $error\n ? theme.color.feedback.negative[200]\n : theme.color.border.contrast};\n }\n\n ${fieldFocusRing}\n ${fieldDisabledStyle}\n\n &::placeholder {\n color: ${({ theme }) => theme.color.text.subtle};\n }\n`\n"]}
@@ -1 +1,2 @@
1
1
  export { Textarea } from './Textarea';
2
+ export type { TextareaProps } from './Textarea';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Textarea/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA","sourcesContent":["export { Textarea } from './Textarea'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Textarea/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA","sourcesContent":["export { Textarea } from './Textarea'\nexport type { TextareaProps } from './Textarea'\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrshmllw/smores-react",
3
- "version": "16.11.4",
3
+ "version": "16.12.0",
4
4
  "description": "Collection of React components used by Marshmallow Technology",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -60,7 +60,7 @@
60
60
  "@mrshmllw/smores-foundations": "^1.2.0",
61
61
  "body-scroll-lock": "^4.0.0-beta.0",
62
62
  "date-fns": "^4.4.0",
63
- "dompurify": "^3.4.16",
63
+ "dompurify": "^3.4.17",
64
64
  "fuse.js": "^7.5.0",
65
65
  "lexical": "^0.52.0",
66
66
  "polished": "^4.3.1"
@@ -69,11 +69,11 @@
69
69
  "@commitlint/cli": "^21.2.3",
70
70
  "@mrshmllw/campfire": "^7.1.0",
71
71
  "@snyk/protect": "^1.1308.0",
72
- "@storybook/addon-a11y": "^10.6.1",
72
+ "@storybook/addon-a11y": "^10.6.2",
73
73
  "@storybook/addon-coverage": "^3.0.2",
74
- "@storybook/addon-docs": "^10.6.1",
75
- "@storybook/addon-links": "^10.6.1",
76
- "@storybook/react-vite": "^10.6.1",
74
+ "@storybook/addon-docs": "^10.6.2",
75
+ "@storybook/addon-links": "^10.6.2",
76
+ "@storybook/react-vite": "^10.6.2",
77
77
  "@storybook/test-runner": "^0.26.0",
78
78
  "@testing-library/jest-dom": "^7.0.1",
79
79
  "@testing-library/react": "^16.3.3",
@@ -96,7 +96,7 @@
96
96
  "react-dom": "^19.3.0",
97
97
  "rimraf": "^6.1.3",
98
98
  "storybook": "^10.2.13",
99
- "styled-components": "^6.5.3",
99
+ "styled-components": "^6.6.0",
100
100
  "typescript": "^7.0.2",
101
101
  "vite": "^8.3.0",
102
102
  "vitest": "^4.1.11"