etudes 1.2.0 → 2.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.
Files changed (126) hide show
  1. package/README.md +1 -1
  2. package/lib/Accordion.d.ts +80 -71
  3. package/lib/Accordion.js +173 -183
  4. package/lib/Accordion.js.map +1 -1
  5. package/lib/BurgerButton.d.ts +20 -7
  6. package/lib/BurgerButton.js +113 -20
  7. package/lib/BurgerButton.js.map +1 -1
  8. package/lib/Conditional.d.ts +2 -3
  9. package/lib/Conditional.js +0 -1
  10. package/lib/Conditional.js.map +1 -1
  11. package/lib/DebugConsole.d.ts +14 -23
  12. package/lib/DebugConsole.js +86 -87
  13. package/lib/DebugConsole.js.map +1 -1
  14. package/lib/Dial.d.ts +53 -16
  15. package/lib/Dial.js +121 -35
  16. package/lib/Dial.js.map +1 -1
  17. package/lib/Dropdown.d.ts +68 -83
  18. package/lib/Dropdown.js +226 -161
  19. package/lib/Dropdown.js.map +1 -1
  20. package/lib/Each.d.ts +2 -2
  21. package/lib/Each.js.map +1 -1
  22. package/lib/ExtractChild.d.ts +5 -4
  23. package/lib/ExtractChild.js +13 -11
  24. package/lib/ExtractChild.js.map +1 -1
  25. package/lib/ExtractChildren.d.ts +2 -2
  26. package/lib/ExtractChildren.js +7 -5
  27. package/lib/ExtractChildren.js.map +1 -1
  28. package/lib/FlatSVG.d.ts +30 -25
  29. package/lib/FlatSVG.js +28 -37
  30. package/lib/FlatSVG.js.map +1 -1
  31. package/lib/List.d.ts +97 -54
  32. package/lib/List.js +124 -63
  33. package/lib/List.js.map +1 -1
  34. package/lib/MasonryGrid.d.ts +27 -15
  35. package/lib/MasonryGrid.js +163 -148
  36. package/lib/MasonryGrid.js.map +1 -1
  37. package/lib/Panorama.d.ts +100 -21
  38. package/lib/Panorama.js +45 -44
  39. package/lib/Panorama.js.map +1 -1
  40. package/lib/PanoramaSlider.d.ts +65 -23
  41. package/lib/PanoramaSlider.js +150 -45
  42. package/lib/PanoramaSlider.js.map +1 -1
  43. package/lib/RangeSlider.d.ts +29 -89
  44. package/lib/RangeSlider.js +272 -286
  45. package/lib/RangeSlider.js.map +1 -1
  46. package/lib/Repeat.d.ts +4 -3
  47. package/lib/Repeat.js +3 -2
  48. package/lib/Repeat.js.map +1 -1
  49. package/lib/RotatingGallery.d.ts +38 -36
  50. package/lib/RotatingGallery.js +47 -17
  51. package/lib/RotatingGallery.js.map +1 -1
  52. package/lib/SelectableButton.d.ts +13 -4
  53. package/lib/SelectableButton.js +3 -14
  54. package/lib/SelectableButton.js.map +1 -1
  55. package/lib/Slider.d.ts +103 -41
  56. package/lib/Slider.js +182 -82
  57. package/lib/Slider.js.map +1 -1
  58. package/lib/StepwiseSlider.d.ts +146 -59
  59. package/lib/StepwiseSlider.js +248 -142
  60. package/lib/StepwiseSlider.js.map +1 -1
  61. package/lib/SwipeContainer.d.ts +13 -5
  62. package/lib/SwipeContainer.js +5 -15
  63. package/lib/SwipeContainer.js.map +1 -1
  64. package/lib/TextField.d.ts +1 -1
  65. package/lib/TextField.js +5 -15
  66. package/lib/TextField.js.map +1 -1
  67. package/lib/Video.d.ts +30 -51
  68. package/lib/Video.js +77 -119
  69. package/lib/Video.js.map +1 -1
  70. package/lib/WithTooltip.d.ts +16 -18
  71. package/lib/WithTooltip.js +167 -101
  72. package/lib/WithTooltip.js.map +1 -1
  73. package/lib/hooks/useDocumentTitle.d.ts +2 -1
  74. package/lib/hooks/useDocumentTitle.js +2 -1
  75. package/lib/hooks/useDocumentTitle.js.map +1 -1
  76. package/lib/hooks/useDragEffect.d.ts +26 -17
  77. package/lib/hooks/useDragEffect.js +30 -20
  78. package/lib/hooks/useDragEffect.js.map +1 -1
  79. package/lib/hooks/useElementRect.d.ts +2 -1
  80. package/lib/hooks/useElementRect.js +5 -4
  81. package/lib/hooks/useElementRect.js.map +1 -1
  82. package/lib/hooks/useInterval.d.ts +3 -3
  83. package/lib/hooks/useInterval.js +1 -1
  84. package/lib/hooks/useInterval.js.map +1 -1
  85. package/lib/hooks/useLoadImageEffect.d.ts +8 -8
  86. package/lib/hooks/useLoadImageEffect.js.map +1 -1
  87. package/lib/hooks/usePrevious.d.ts +6 -0
  88. package/lib/hooks/usePrevious.js +17 -0
  89. package/lib/hooks/usePrevious.js.map +1 -0
  90. package/lib/hooks/useResizeEffect.d.ts +3 -3
  91. package/lib/hooks/useResizeEffect.js +5 -8
  92. package/lib/hooks/useResizeEffect.js.map +1 -1
  93. package/lib/hooks/useSearchParamState.d.ts +11 -8
  94. package/lib/hooks/useSearchParamState.js +14 -10
  95. package/lib/hooks/useSearchParamState.js.map +1 -1
  96. package/lib/providers/I18nProvider.d.ts +179 -0
  97. package/lib/providers/I18nProvider.js +470 -0
  98. package/lib/providers/I18nProvider.js.map +1 -0
  99. package/lib/providers/ScrollPositionProvider.d.ts +15 -0
  100. package/lib/providers/ScrollPositionProvider.js +112 -0
  101. package/lib/providers/ScrollPositionProvider.js.map +1 -0
  102. package/lib/utils/asClassNameDict.d.ts +3 -0
  103. package/lib/utils/asClassNameDict.js +7 -0
  104. package/lib/utils/asClassNameDict.js.map +1 -0
  105. package/lib/utils/asComponentDict.d.ts +5 -0
  106. package/lib/utils/asComponentDict.js +23 -0
  107. package/lib/utils/asComponentDict.js.map +1 -0
  108. package/lib/utils/asStyleDict.d.ts +4 -0
  109. package/lib/utils/asStyleDict.js +7 -0
  110. package/lib/utils/asStyleDict.js.map +1 -0
  111. package/lib/utils/cloneStyledElement.d.ts +18 -0
  112. package/lib/utils/cloneStyledElement.js +63 -0
  113. package/lib/utils/cloneStyledElement.js.map +1 -0
  114. package/lib/utils/styles.d.ts +2 -0
  115. package/lib/utils/styles.js +22 -0
  116. package/lib/utils/styles.js.map +1 -0
  117. package/lib/utils/useDebug.d.ts +2 -0
  118. package/lib/utils/useDebug.js +46 -0
  119. package/lib/utils/useDebug.js.map +1 -0
  120. package/package.json +31 -38
  121. package/lib/AbstractSelectableCollection.d.ts +0 -94
  122. package/lib/AbstractSelectableCollection.js +0 -151
  123. package/lib/AbstractSelectableCollection.js.map +0 -1
  124. package/lib/types/index.d.ts +0 -7
  125. package/lib/types/index.js +0 -3
  126. package/lib/types/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.js","sourceRoot":"/","sources":["Dropdown.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAsE;AACtE,+BAA4B;AAC5B,qEAA8D;AAC9D,gDAA2E;AAoI3E;;;;GAIG;AACH;IAA+D,4BAA8B;IAK3F,kBAAY,KAAe;QAA3B,iBAOC;;gBANC,kBAAM,KAAK,CAAC;QALd,cAAQ,GAAG;YACT,IAAI,EAAE,IAAA,iBAAS,GAAkB;SAClC,CAAA;QAoJD;;;;;WAKG;QACK,oBAAc,GAAG,UAAC,KAAiB;YACzC,IAAI,KAAI,CAAC,KAAK,CAAC,WAAW;gBAAE,OAAM;YAClC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,IAAI,CAAC;gBAAE,OAAM;YAE3C,IAAI,SAAS,GAAG,IAAI,CAAA;YACpB,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,CAAA;YAEvB,OAAO,IAAI,EAAE;gBACX,IAAI,IAAI,KAAK,KAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE;oBACvC,SAAS,GAAG,KAAK,CAAA;oBACjB,MAAK;iBACN;gBAED,IAAI,CAAC,IAAI,CAAC,UAAU;oBAAE,MAAK;gBAE3B,IAAI,GAAG,IAAI,CAAC,UAAU,CAAA;aACvB;YAED,IAAI,CAAC,SAAS;gBAAE,OAAM;YAEtB,KAAI,CAAC,QAAQ,EAAE,CAAA;QACjB,CAAC,CAAA;QA1KC,KAAI,CAAC,KAAK,GAAG;YACX,iBAAiB,EAAE,MAAA,KAAI,CAAC,KAAK,CAAC,wBAAwB,mCAAI,CAAC,CAAC;YAC5D,WAAW,EAAE,IAAI;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AwB,EAmBjC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,eAAe,GAAG,CAAC,QAAI,uBAAG,0GAAA,gBAC/B,EAAqB,WAAY,EAAiB,OAC7D,KADW,KAAK,CAAC,eAAe,EAAY,KAAK,CAAC,WAAW,CAC7D,EAFU,CAEV,CAYF,CAAA;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,oPAG3B,yKASE,EAQD,IACF,KATG,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,KAAC,uBAAG,6IAAA,wBAC7B,EAA8C,6CAGjE,KAHmB,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,QAAQ,EAGhE,CAAC,KAAC,uBAAG,6IAAA,wBACa,EAAwC,6CAG3D,KAHmB,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAG3D,EARU,CAQV,CACF,CAAA","sourcesContent":["import React, { ComponentType, createRef, PureComponent } from 'react'\nimport { Rect } from 'spase'\nimport styled, { css, CSSProperties } from 'styled-components'\nimport List, { ItemComponentProps as ListItemComponentProps } from './List'\nimport { ExtendedCSSFunction, ExtendedCSSProps, Orientation } from './types'\n\nexport type ButtonCSSProps = Readonly<{\n borderColor: string\n borderThickness: number\n isActive: boolean\n}>\n\n/**\n * Type constraint of the data passed to each item in the component.\n */\nexport type DataProps<T = Record<string, any>> = T & {\n label?: string\n}\n\n/**\n * Interface defining the props of the item component type to be provided to the\n * component. The data type is generic.\n */\nexport type ItemComponentProps<T = Record<string, any>> = ListItemComponentProps<DataProps<T>>\n\nexport type Props<T = Record<string, any>> = {\n /**\n * Class attribute to the root element.\n */\n className?: string\n\n /**\n * Inline style attribute to the element.\n */\n style?: CSSProperties\n\n /**\n * Data of every item in the component. This is used to generate individual\n * menu items. Data type is generic.\n */\n data: DataProps<T>[]\n\n /**\n * Indicates if the component is inverted (i.e. \"dropup\" instead of dropdown).\n * Supports all orientations.\n */\n isInverted?: boolean\n\n /**\n * Indicates if items can be toggled, i.e. they can be deselected if selected\n * again.\n */\n isTogglable?: boolean\n\n /**\n * Thickness of the border (in pixels) of every item and the dropdown button\n * itself. 0 indicates no borders.\n */\n borderThickness?: number\n\n /**\n * The index of the default selected item.\n */\n defaultSelectedItemIndex?: number\n\n /**\n * Length (in pixels) of each item. This does not apply to the dropdown button\n * itself. Length refers to the height in vertical orientation and width in\n * horizontal orientation.\n */\n itemLength?: number\n\n /**\n * Padding (in pixels) of each item.\n */\n itemPadding?: number\n\n /**\n * Maximum number of items that are viside when the component expands. When a\n * value greater than or equal to 0 is specified, only that number of items\n * will be visible at a time, and a scrollbar will appear to scroll to\n * remaining items. Any value less than 0 indicates that all items will be\n * visible when the component expands.\n */\n maxVisibleItems?: number\n\n /**\n * Orientation of the component.\n */\n orientation?: Orientation\n\n /**\n * Color of the border of every item and the dropdown button itself.\n */\n borderColor?: string\n\n /**\n * The label to appear on the dropdown button when no items are selected.\n */\n defaultLabel?: string\n\n /**\n * SVG markup to be put in the dropdown button as the expand icon.\n */\n expandIconSvg?: string\n\n /**\n * React component type to be used for generating items inside the component.\n */\n itemComponentType: ComponentType<ItemComponentProps<T>>\n\n /**\n * Handler invoked whenever the selected index changes.\n */\n onIndexChange?: (index: number) => void\n\n /**\n * Additional CSS to be provided to the dropdown button.\n */\n buttonCSS?: ExtendedCSSFunction<ButtonCSSProps>\n}\n\nexport interface State {\n /**\n * Index of the currently selected item. Any value less than 0 indicates that\n * no item is selected.\n */\n selectedItemIndex: number\n\n /**\n * Indicates if the dropdown menu is collapsed.\n */\n isCollapsed: boolean\n}\n\n/**\n * A dropdown menu component that is invertible (i.e. can \"dropup\" instead) and\n * supports both horizontal and vertical orientations. Provide data and item\n * component type to this component to automatically generate menu items.\n */\nexport default class Dropdown<T = Record<string, any>> extends PureComponent<Props<T>, State> {\n nodeRefs = {\n root: createRef<HTMLDivElement>(),\n }\n\n constructor(props: Props<T>) {\n super(props)\n\n this.state = {\n selectedItemIndex: this.props.defaultSelectedItemIndex ?? -1,\n isCollapsed: true,\n }\n }\n\n get rect(): Rect {\n return Rect.from(this.nodeRefs.root.current) ?? new Rect()\n }\n\n componentDidMount() {\n window.addEventListener('click', this.onClickOutside)\n this.props.onIndexChange?.(this.state.selectedItemIndex)\n }\n\n componentWillUnmount() {\n window.removeEventListener('click', this.onClickOutside)\n }\n\n componentDidUpdate(prevProps: Props<T>, prevState: State) {\n if (prevState.selectedItemIndex !== this.state.selectedItemIndex) {\n this.props.onIndexChange?.(this.state.selectedItemIndex)\n }\n\n if (prevProps.orientation !== this.props.orientation) {\n this.forceUpdate()\n }\n }\n\n render() {\n const borderColor = this.props.borderColor ?? '#000'\n const borderThickness = this.props.borderThickness ?? 1\n const orientation = this.props.orientation ?? 'vertical'\n const itemLength = this.props.itemLength ?? (orientation === 'vertical' ? this.rect.height : this.rect.width)\n const maxVisibleItems = this.props.maxVisibleItems ?? -1\n const isTogglable = this.props.isTogglable ?? true\n const itemPadding = this.props.itemPadding ?? 0\n const numItems = this.props.data.length\n const numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems)\n const menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness\n\n return (\n <StyledRoot\n className={this.props.className}\n orientation={orientation}\n isInverted={this.props.isInverted ?? false}\n ref={this.nodeRefs.root}\n style={this.props.style ?? {}}\n >\n <StyledToggle\n borderColor={borderColor}\n borderThickness={borderThickness}\n extendedCSS={this.props.buttonCSS ?? (() => css``)}\n isActive={!this.state.isCollapsed}\n onClick={() => this.toggle()}\n >\n <label>\n {this.state.selectedItemIndex === -1 ? (this.props.defaultLabel ?? 'Select') : this.props.data[this.state.selectedItemIndex].label}\n </label>\n {this.props.expandIconSvg && <span dangerouslySetInnerHTML={{ __html: this.props.expandIconSvg }}/>}\n </StyledToggle>\n <StyledItemList\n borderColor={borderColor}\n borderThickness={borderThickness}\n data={this.props.data}\n defaultSelectedIndex={this.props.defaultSelectedItemIndex ?? -1}\n isInverted={this.props.isInverted ?? false}\n isTogglable={isTogglable}\n itemComponentType={this.props.itemComponentType as any} // HACK: Generic types cannot be inferred by props, so this is the only way.\n itemPadding={itemPadding}\n onDeselectAt={idx => this.selectItemAt(-1)}\n onSelectAt={idx => this.selectItemAt(idx)}\n orientation={orientation}\n shouldStaySelected={true}\n itemStyle={orientation === 'vertical' ? {\n height: `${itemLength}px`,\n } : {\n width: `${itemLength}px`,\n }}\n style={orientation === 'vertical' ? {\n height: this.state.isCollapsed ? '0px' : `${menuLength}px`,\n overflowY: (maxVisibleItems === -1) ? 'hidden' : (maxVisibleItems < numItems ? 'scroll' : 'hidden'),\n } : {\n width: this.state.isCollapsed ? '0px' : `${menuLength}px`,\n overflowX: (maxVisibleItems === -1) ? 'hidden' : (maxVisibleItems < numItems ? 'scroll' : 'hidden'),\n }}\n />\n </StyledRoot>\n )\n }\n\n /**\n * Indicates if the item at the specified index is selected.\n *\n * @param index - The index of the item.\n *\n * @returns `true` if the item at the specified index is selected, `false`\n * otherwise.\n */\n isItemSelectedAt(index: number) {\n return (this.state.selectedItemIndex === index)\n }\n\n /**\n * Selects the item at the specified index.\n *\n * @param index - The index of the item to select.\n */\n selectItemAt(index: number) {\n this.setState({\n selectedItemIndex: index,\n isCollapsed: true,\n })\n }\n\n /**\n * Expands the menu, revealing its items.\n */\n expand() {\n if (!this.state.isCollapsed) return\n this.setState({ isCollapsed: false })\n }\n\n /**\n * Collapses the menu, concealing its items.\n */\n collapse() {\n if (this.state.isCollapsed) return\n this.setState({ isCollapsed: true })\n }\n\n /**\n * Toggles the visibility of the menu.\n */\n toggle() {\n if (this.state.isCollapsed) {\n this.expand()\n }\n else {\n this.collapse()\n }\n }\n\n /**\n * Handler invoked when click input is detected outside of the root element\n * of the component.\n *\n * @param event - The MouseEvent passed to the handler.\n */\n private onClickOutside = (event: MouseEvent) => {\n if (this.state.isCollapsed) return\n if (!(event.target instanceof Node)) return\n\n let isOutside = true\n let node = event.target\n\n while (node) {\n if (node === this.nodeRefs.root.current) {\n isOutside = false\n break\n }\n\n if (!node.parentNode) break\n\n node = node.parentNode\n }\n\n if (!isOutside) return\n\n this.collapse()\n }\n}\n\nconst StyledItemList = styled(List)<{\n isInverted: boolean\n itemPadding: number\n borderThickness: number\n orientation: Orientation\n}>`\n position: absolute;\n\n ::-webkit-scrollbar {}\n ::-webkit-scrollbar-track {}\n ::-webkit-scrollbar-thumb {}\n ::-webkit-scrollbar-hover {}\n\n ${props => props.orientation === 'vertical' ? css`\n transition: height 100ms ease-out;\n will-change: height;\n\n ${props.isInverted ? css`\n margin-bottom: ${props.itemPadding - props.borderThickness}px;\n bottom: 100%;\n ` : css`\n top: 100%;\n margin-top: ${props.itemPadding - props.borderThickness}px;\n `}\n ` : css`\n transition: width 100ms ease-out;\n will-change: width;\n\n ${props.isInverted ? css`\n margin-right: ${props.itemPadding - props.borderThickness}px;\n right: 100%;\n ` : css`\n left: 100%;\n margin-left: ${props.itemPadding - props.borderThickness}px;\n `}\n `}\n`\n\nconst StyledToggle = styled.button<ButtonCSSProps & ExtendedCSSProps<ButtonCSSProps>>`\n > span {\n height: 15px;\n width: 15px;\n }\n\n > label {\n font-family: inherit;\n font-size: inherit;\n font-weight: inherit;\n letter-spacing: inherit;\n line-height: inherit;\n }\n\n ${props => props.extendedCSS(props)}\n\n align-items: center;\n background: #fff;\n box-sizing: border-box;\n color: #000;\n display: flex;\n flex-direction: row;\n height: 100%;\n justify-content: space-between;\n left: 0;\n margin: 0;\n outline: none;\n padding: 0 10px;\n position: absolute;\n top: 0;\n width: 100%;\n z-index: 1;\n\n ${props => props.borderThickness > 0 && css`\n border: ${props.borderThickness}px solid ${props.borderColor};\n `}\n\n > span {\n box-sizing: border-box;\n display: block;\n transform-origin: center;\n\n svg {\n height: 100%;\n width: auto;\n }\n }\n`\n\nconst StyledRoot = styled.div<{\n isInverted: boolean\n orientation: Orientation\n}>`\n align-items: center;\n box-sizing: border-box;\n display: flex;\n justify-content: flex-start;\n padding: 0;\n overflow: visible;\n position: relative;\n\n ${props => props.orientation === 'vertical' ? css`\n flex-direction: ${props.isInverted ? 'column-reverse' : 'column'};\n height: 50px;\n width: 200px;\n ` : css`\n flex-direction: ${props.isInverted ? 'row-reverse' : 'row'};\n height: 200px;\n width: 50px;\n `}\n`\n"]}
1
+ {"version":3,"file":"Dropdown.js","sourceRoot":"/","sources":["Dropdown.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAA2I;AAC3I,sDAA+B;AAC/B,0EAAmD;AACnD,gDAA4C;AAC5C,4EAAqD;AACrD,4EAAqD;AACrD,oEAA6C;AAC7C,kFAA2D;AAC3D,0DAAmC;AAuFnC;;;;GAIG;AACH,kBAAe,IAAA,kBAAU,EAAC,UAAC,EAkB1B,EAAE,GAAG;;IAjBJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,KAAK,WAAA,EACL,uBAAmB,EAAnB,eAAe,mBAAG,CAAC,KAAA,EACnB,IAAI,UAAA,EACJ,oBAAuB,EAAvB,YAAY,mBAAG,QAAQ,KAAA,EACvB,aAAa,mBAAA,EACb,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,mBAAmB,EAAnB,WAAW,mBAAG,KAAK,KAAA,EACnB,iBAAiB,uBAAA,EACL,kBAAkB,gBAAA,EAC9B,mBAAe,EAAf,WAAW,mBAAG,CAAC,KAAA,EACf,uBAAoB,EAApB,eAAe,mBAAG,CAAC,CAAC,KAAA,EACpB,mBAAwB,EAAxB,WAAW,mBAAG,UAAU,KAAA,EACxB,qBAAyC,EAA1B,qBAAqB,mBAAG,CAAC,CAAC,KAAA,EACzC,aAAa,mBAAA,EACV,KAAK,cAjBiB,iPAkB1B,CADS;IAER,IAAM,YAAY,GAAG,UA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,cAAV,EAAY,CAAF;IAAuC,OAAA,kDAAS,KAAK,EAAG,CAAA;CAAA,CAAA;AAAxF,QAAA,kBAAkB,sBAAsE","sourcesContent":["import classNames from 'classnames'\nimport React, { ComponentType, forwardRef, HTMLAttributes, PropsWithChildren, ReactElement, Ref, useEffect, useRef, useState } from 'react'\nimport FlatSVG from './FlatSVG'\nimport useElementRect from './hooks/useElementRect'\nimport List, { ListItemProps } from './List'\nimport asClassNameDict from './utils/asClassNameDict'\nimport asComponentDict from './utils/asComponentDict'\nimport asStyleDict from './utils/asStyleDict'\nimport cloneStyledElement from './utils/cloneStyledElement'\nimport styles from './utils/styles'\n\ntype Orientation = 'horizontal' | 'vertical'\n\nexport type DropdownData = {\n label?: string\n}\n\nexport type DropdownItemProps<T extends DropdownData = DropdownData> = ListItemProps<T>\n\nexport type DropdownProps<T extends DropdownData = DropdownData> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n /**\n * Data of every item in the component. This is used to generate individual\n * menu items. Data type is generic.\n */\n data: T[]\n\n /**\n * Indicates if the component is inverted (i.e. \"dropup\" instead of dropdown).\n * Supports all orientations.\n */\n isInverted?: boolean\n\n /**\n * Indicates if items can be toggled, i.e. they can be deselected if selected\n * again.\n */\n isTogglable?: boolean\n\n /**\n * Thickness of the border (in pixels) of every item and the dropdown button\n * itself. 0 indicates no borders.\n */\n borderThickness?: number\n\n /**\n * The index of the default selected item.\n */\n selectedIndex?: number\n\n /**\n * Length (in pixels) of each item. This does not apply to the dropdown button\n * itself. Length refers to the height in vertical orientation and width in\n * horizontal orientation.\n */\n itemLength?: number\n\n /**\n * Padding (in pixels) of each item.\n */\n itemPadding?: number\n\n /**\n * Maximum number of items that are viside when the component expands. When a\n * value greater than or equal to 0 is specified, only that number of items\n * will be visible at a time, and a scrollbar will appear to scroll to\n * remaining items. Any value less than 0 indicates that all items will be\n * visible when the component expands.\n */\n maxVisibleItems?: number\n\n /**\n * Orientation of the component.\n */\n orientation?: Orientation\n\n /**\n * The label to appear on the dropdown button when no items are selected.\n */\n defaultLabel?: string\n\n /**\n * SVG markup to be put in the dropdown button as the expand icon.\n */\n expandIconSvg?: string\n\n /**\n * React component type to be used for generating items inside the component.\n */\n itemComponentType: ComponentType<DropdownItemProps<T>>\n\n /**\n * Handler invoked whenever the selected index changes.\n */\n onIndexChange?: (index: number) => void\n}>\n\n/**\n * A dropdown menu component that is invertible (i.e. can \"dropup\" instead) and\n * supports both horizontal and vertical orientations. Provide data and item\n * component type to this component to automatically generate menu items.\n */\nexport default forwardRef(({\n children,\n className,\n style,\n borderThickness = 0,\n data,\n defaultLabel = 'Select',\n expandIconSvg,\n isInverted = false,\n isTogglable = false,\n itemComponentType,\n itemLength: externalItemLength,\n itemPadding = 0,\n maxVisibleItems = -1,\n orientation = 'vertical',\n selectedIndex: externalSelectedIndex = -1,\n onIndexChange,\n ...props\n}, ref) => {\n const selectItemAt = (index: number) => {\n setSelectedIndex(index)\n setIsCollapsed(true)\n }\n\n const expand = () => {\n if (!isCollapsed) return\n setIsCollapsed(false)\n }\n\n const collapse = () => {\n if (isCollapsed) return\n setIsCollapsed(true)\n }\n\n const toggle = () => {\n if (isCollapsed) {\n expand()\n }\n else {\n collapse()\n }\n }\n\n const clickOutsideHandler = (event: MouseEvent) => {\n if (isCollapsed) return\n if (!(event.target instanceof Node)) return\n\n let isOutside = true\n let node = event.target\n\n while (node) {\n if (node === bodyRef.current) {\n isOutside = false\n break\n }\n\n if (!node.parentNode) break\n\n node = node.parentNode\n }\n\n if (!isOutside) return\n\n collapse()\n }\n\n const bodyRef = useRef<HTMLDivElement>(null)\n const [selectedIndex, setSelectedIndex] = useState(externalSelectedIndex)\n const [isCollapsed, setIsCollapsed] = useState(true)\n const rect = useElementRect(bodyRef)\n\n useEffect(() => {\n window.addEventListener('click', clickOutsideHandler)\n\n return () => {\n window.removeEventListener('click', clickOutsideHandler)\n }\n }, [isCollapsed])\n\n useEffect(() => {\n if (externalSelectedIndex === selectedIndex) return\n setSelectedIndex(externalSelectedIndex)\n }, [externalSelectedIndex])\n\n useEffect(() => {\n onIndexChange?.(selectedIndex)\n }, [selectedIndex])\n\n const itemLength = externalItemLength ?? (orientation === 'vertical' ? rect.height : rect.width)\n const numItems = data.length\n const numVisibleItems = maxVisibleItems < 0 ? numItems : Math.min(numItems, maxVisibleItems)\n const menuLength = (itemLength - borderThickness) * numVisibleItems + itemPadding * (numVisibleItems - 1) + borderThickness\n\n const components = asComponentDict(children, {\n toggle: DropdownToggle,\n expandIcon: DropdownExpandIcon,\n })\n\n const fixedClassNames = asClassNameDict({\n root: classNames(orientation, {\n togglable: isTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n toggle: classNames(orientation, {\n togglable: isTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n expandIcon: classNames(orientation, {\n togglable: isTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n list: classNames({\n togglable: isTogglable,\n collapsed: isCollapsed,\n expanded: !isCollapsed,\n }),\n })\n\n const fixedStyles = asStyleDict({\n root: {\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'flex-start',\n overflow: 'visible',\n ...orientation === 'vertical' ? {\n flexDirection: isInverted ? 'column-reverse' : 'column',\n } : {\n flexDirection: isInverted ? 'row-reverse' : 'row',\n },\n },\n body: {\n height: '100%',\n width: '100%',\n },\n toggle: {\n borderWidth: `${borderThickness}px`,\n height: '100%',\n left: '0',\n margin: '0',\n outline: 'none',\n position: 'absolute',\n top: '0',\n width: '100%',\n zIndex: '1',\n },\n toggleLabel: {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n fontWeight: 'inherit',\n letterSpacing: 'inherit',\n lineHeight: 'inherit',\n },\n expandIcon: {\n\n },\n list: {\n position: 'absolute',\n ...orientation === 'vertical' ? {\n transition: 'height 100ms ease-out',\n width: '100%',\n height: isCollapsed ? '0px' : `${menuLength}px`,\n overflowY: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n ...isInverted ? {\n marginBottom: `${itemPadding - borderThickness}px`,\n bottom: '100%',\n } : {\n top: '100%',\n marginTop: `${itemPadding - borderThickness}px`,\n },\n } : {\n transition: 'width 100ms ease-out',\n width: isCollapsed ? '0px' : `${menuLength}px`,\n height: '100%',\n overflowX: maxVisibleItems === -1 ? 'hidden' : maxVisibleItems < numItems ? 'scroll' : 'hidden',\n ...isInverted ? {\n marginRight: `${itemPadding - borderThickness}px`,\n right: '100%',\n } : {\n left: '100%',\n marginLeft: `${itemPadding - borderThickness}px`,\n },\n },\n },\n })\n\n const defaultStyles = asStyleDict({\n toggle: {\n alignItems: 'center',\n background: '#fff',\n boxSizing: 'border-box',\n color: '#000',\n display: 'flex',\n flexDirection: 'row',\n fontSize: '16px',\n justifyContent: 'space-between',\n margin: '0',\n padding: '0 10px',\n },\n expandIcon: {\n height: '15px',\n margin: '0',\n padding: '0',\n width: '15px',\n },\n })\n\n return (\n <div\n {...props}\n ref={ref}\n className={classNames(className, fixedClassNames.root)}\n style={styles(style, fixedStyles.root)}\n >\n <div ref={bodyRef} style={styles(fixedStyles.body)}>\n {cloneStyledElement(components.toggle ?? <button style={defaultStyles.toggle}/>, {\n className: classNames(fixedClassNames.toggle),\n style: styles(fixedStyles.toggle),\n onClick: () => toggle(),\n }, ...[\n <label style={fixedStyles.toggleLabel} dangerouslySetInnerHTML={{ __html: selectedIndex === -1 ? defaultLabel : data[selectedIndex].label ?? '' }}/>,\n cloneStyledElement(components.expandIcon ?? (expandIconSvg ? <FlatSVG svg={expandIconSvg} style={defaultStyles.expandIcon}/> : <></>), {\n className: classNames(fixedClassNames.expandIcon),\n style: styles(fixedStyles.expandIcon),\n }),\n ])}\n <List\n className={fixedClassNames.list}\n style={styles(fixedStyles.list)}\n borderThickness={borderThickness}\n data={data}\n isSelectable={true}\n isTogglable={false}\n itemComponentType={itemComponentType}\n itemLength={itemLength}\n itemPadding={itemPadding}\n orientation={orientation}\n selectedIndex={selectedIndex}\n onDeselectAt={idx => selectItemAt(-1)}\n onSelectAt={idx => selectItemAt(idx)}\n />\n </div>\n </div>\n )\n}) as <T extends DropdownData = DropdownData>(props: DropdownProps<T> & { ref?: Ref<HTMLDivElement> }) => ReactElement\n\nexport const DropdownToggle = ({ ...props }: HTMLAttributes<HTMLButtonElement>) => <button {...props}/>\n\nexport const DropdownExpandIcon = ({ ...props }: HTMLAttributes<HTMLDivElement>) => <div {...props}/>\n"]}
package/lib/Each.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
- export declare type Props<T> = {
2
+ export type EachProps<T> = {
3
3
  children?: ReactNode | ((value: T, index: number) => ReactNode);
4
4
  in?: T[];
5
5
  render?: (value: T, index: number) => ReactNode;
6
6
  };
7
- export default function Each<T>({ in: array, children, render, }: Props<T>): JSX.Element;
7
+ export default function Each<T>({ in: array, children, render, }: EachProps<T>): JSX.Element;
package/lib/Each.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Each.js","sourceRoot":"/","sources":["Each.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAkD;AAQlD,SAAwB,IAAI,CAAI,EAIrB;QAHL,KAAK,QAAA,EACT,QAAQ,cAAA,EACR,MAAM,YAAA;IAEN,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,6DAAK,CAAA;IACvD,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,MAAM,SAAS,CAAC,yBAAkB,KAAK,sBAAmB,CAAC,CAAA;IAE1F,OAAO,CACL,8DACG,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CACnB,8BAAC,gBAAQ,IAAC,GAAG,EAAE,eAAQ,CAAC,CAAE,IACvB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAC1E,CACZ,EAJoB,CAIpB,CAAC,CACD,CACJ,CAAA;AACH,CAAC;AAjBD,uBAiBC","sourcesContent":["import React, { Fragment, ReactNode } from 'react'\n\nexport type Props<T> = {\n children?: ReactNode | ((value: T, index: number) => ReactNode)\n in?: T[]\n render?: (value: T, index: number) => ReactNode\n}\n\nexport default function Each<T>({\n in: array,\n children,\n render,\n}: Props<T>) {\n if (array === undefined || array === null) return <></>\n if (!(array instanceof Array)) throw TypeError(`Provided list <${array}> is not an array`)\n\n return (\n <>\n {array.map((v, i) => (\n <Fragment key={`item-${i}`}>\n {render ? render(v, i) : typeof children === 'function' ? children(v, i) : children}\n </Fragment>\n ))}\n </>\n )\n}\n"]}
1
+ {"version":3,"file":"Each.js","sourceRoot":"/","sources":["Each.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAkD;AAQlD,SAAwB,IAAI,CAAI,EAIjB;QAHT,KAAK,QAAA,EACT,QAAQ,cAAA,EACR,MAAM,YAAA;IAEN,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,6DAAK,CAAA;IACvD,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,MAAM,SAAS,CAAC,yBAAkB,KAAK,sBAAmB,CAAC,CAAA;IAE1F,OAAO,CACL,8DACG,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CACnB,8BAAC,gBAAQ,IAAC,GAAG,EAAE,eAAQ,CAAC,CAAE,IACvB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAC1E,CACZ,EAJoB,CAIpB,CAAC,CACD,CACJ,CAAA;AACH,CAAC;AAjBD,uBAiBC","sourcesContent":["import React, { Fragment, ReactNode } from 'react'\n\nexport type EachProps<T> = {\n children?: ReactNode | ((value: T, index: number) => ReactNode)\n in?: T[]\n render?: (value: T, index: number) => ReactNode\n}\n\nexport default function Each<T>({\n in: array,\n children,\n render,\n}: EachProps<T>) {\n if (array === undefined || array === null) return <></>\n if (!(array instanceof Array)) throw TypeError(`Provided list <${array}> is not an array`)\n\n return (\n <>\n {array.map((v, i) => (\n <Fragment key={`item-${i}`}>\n {render ? render(v, i) : typeof children === 'function' ? children(v, i) : children}\n </Fragment>\n ))}\n </>\n )\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type Props = HTMLAttributes<HTMLElement>;
2
+ export type ExtractChildProps = HTMLAttributes<HTMLElement>;
3
3
  /**
4
- * Extracts a single child of a parent component into its own component. If the parent component has
5
- * multiple children, only the first one will be extracted, the rest will be ignored.
4
+ * Extracts a single child of a parent component into its own component. If the
5
+ * parent component has multiple children, only the first one will be extracted,
6
+ * the rest will be ignored.
6
7
  */
7
- declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLElement>>;
8
+ declare const _default: React.ForwardRefExoticComponent<ExtractChildProps & React.RefAttributes<HTMLElement>>;
8
9
  export default _default;
@@ -48,26 +48,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
49
  };
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
- var classnames_1 = __importDefault(require("classnames"));
52
- var lodash_1 = __importDefault(require("lodash"));
53
51
  var react_1 = __importStar(require("react"));
52
+ var cloneStyledElement_1 = __importDefault(require("./utils/cloneStyledElement"));
54
53
  /**
55
- * Extracts a single child of a parent component into its own component. If the parent component has
56
- * multiple children, only the first one will be extracted, the rest will be ignored.
54
+ * Extracts a single child of a parent component into its own component. If the
55
+ * parent component has multiple children, only the first one will be extracted,
56
+ * the rest will be ignored.
57
57
  */
58
58
  exports.default = (0, react_1.forwardRef)(function (_a, ref) {
59
- var children = _a.children, className = _a.className, props = __rest(_a, ["children", "className"]);
60
- if (lodash_1.default.isArray(children)) {
61
- /* eslint-disable-next-line no-console */
59
+ var children = _a.children, props = __rest(_a, ["children"]);
60
+ if (Array.isArray(children)) {
62
61
  console.error("[etudes::ExtractChild] Only one child is expected, but found ".concat(children.length, ". Only the first child is extracted while the rest are discarded."));
63
62
  }
64
63
  return (react_1.default.createElement(react_1.default.Fragment, null, react_1.Children.map(children, function (child, idx) {
65
- if (idx > 0)
64
+ if (idx > 0) {
66
65
  return undefined;
67
- if ((0, react_1.isValidElement)(child)) {
68
- return (0, react_1.cloneElement)(child, __assign(__assign({ className: (0, classnames_1.default)(className, child.props.className) }, props), { ref: ref }));
69
66
  }
70
- return child;
67
+ else if ((0, react_1.isValidElement)(child)) {
68
+ return (0, cloneStyledElement_1.default)(child, __assign(__assign({}, props), { ref: ref }));
69
+ }
70
+ else {
71
+ return child;
72
+ }
71
73
  })));
72
74
  });
73
75
  //# sourceMappingURL=ExtractChild.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExtractChild.js","sourceRoot":"/","sources":["ExtractChild.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,kDAAsB;AACtB,6CAAiG;AAIjG;;;GAGG;AACH,kBAAe,IAAA,kBAAU,EAAqB,UAAC,EAI9C,EAAE,GAAG;IAHJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACN,KAAK,cAHqC,yBAI9C,CADS;IAER,IAAI,gBAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACvB,yCAAyC;QACzC,OAAO,CAAC,KAAK,CAAC,uEAAgE,QAAQ,CAAC,MAAM,sEAAmE,CAAC,CAAA;KAClK;IAED,OAAO,CACL,8DACG,gBAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAC,KAAK,EAAE,GAAG;QACjC,IAAI,GAAG,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;QAE7B,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,oBAAY,EAAC,KAAK,sBAAI,SAAS,EAAE,IAAA,oBAAU,EAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,IAAK,KAAK,KAAE,GAAG,KAAA,IAAG,CAAA;SACvG;QAED,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CACD,CACJ,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import classNames from 'classnames'\nimport _ from 'lodash'\nimport React, { Children, cloneElement, forwardRef, HTMLAttributes, isValidElement } from 'react'\n\nexport type Props = HTMLAttributes<HTMLElement>\n\n/**\n * Extracts a single child of a parent component into its own component. If the parent component has\n * multiple children, only the first one will be extracted, the rest will be ignored.\n */\nexport default forwardRef<HTMLElement, Props>(({\n children,\n className,\n ...props\n}, ref) => {\n if (_.isArray(children)) {\n /* eslint-disable-next-line no-console */\n console.error(`[etudes::ExtractChild] Only one child is expected, but found ${children.length}. Only the first child is extracted while the rest are discarded.`)\n }\n\n return (\n <>\n {Children.map(children, (child, idx) => {\n if (idx > 0) return undefined\n\n if (isValidElement(child)) {\n return cloneElement(child, { className: classNames(className, child.props.className), ...props, ref })\n }\n\n return child\n })}\n </>\n )\n})\n"]}
1
+ {"version":3,"file":"ExtractChild.js","sourceRoot":"/","sources":["ExtractChild.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAmF;AACnF,kFAA2D;AAI3D;;;;GAIG;AACH,kBAAe,IAAA,kBAAU,EAAiC,UAAC,EAG1D,EAAE,GAAG;IAFJ,IAAA,QAAQ,cAAA,EACL,KAAK,cAFiD,YAG1D,CADS;IAER,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,uEAAgE,QAAQ,CAAC,MAAM,sEAAmE,CAAC,CAAA;KAClK;IAED,OAAO,CACL,8DACG,gBAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAC,KAAK,EAAE,GAAG;QACjC,IAAI,GAAG,GAAG,CAAC,EAAE;YACX,OAAO,SAAS,CAAA;SACjB;aACI,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE;YAC9B,OAAO,IAAA,4BAAkB,EAAC,KAAK,EAAE,sBAAK,KAAK,KAAE,GAAG,KAAA,GAAS,CAAC,CAAA;SAC3D;aACI;YACH,OAAO,KAAK,CAAA;SACb;IACH,CAAC,CAAC,CACD,CACJ,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { Children, forwardRef, HTMLAttributes, isValidElement } from 'react'\nimport cloneStyledElement from './utils/cloneStyledElement'\n\nexport type ExtractChildProps = HTMLAttributes<HTMLElement>\n\n/**\n * Extracts a single child of a parent component into its own component. If the\n * parent component has multiple children, only the first one will be extracted,\n * the rest will be ignored.\n */\nexport default forwardRef<HTMLElement, ExtractChildProps>(({\n children,\n ...props\n}, ref) => {\n if (Array.isArray(children)) {\n console.error(`[etudes::ExtractChild] Only one child is expected, but found ${children.length}. Only the first child is extracted while the rest are discarded.`)\n }\n\n return (\n <>\n {Children.map(children, (child, idx) => {\n if (idx > 0) {\n return undefined\n }\n else if (isValidElement(child)) {\n return cloneStyledElement(child, { ...props, ref } as any)\n }\n else {\n return child\n }\n })}\n </>\n )\n})\n"]}
@@ -1,6 +1,6 @@
1
1
  import { HTMLAttributes } from 'react';
2
- export declare type Props = HTMLAttributes<HTMLElement>;
2
+ export type ExtractChildrenProps = HTMLAttributes<HTMLElement>;
3
3
  /**
4
4
  * Extracts all children of a parent component into its own component.
5
5
  */
6
- export default function ExtractChildren({ children, className, ...props }: Props): JSX.Element;
6
+ export default function ExtractChildren({ children, ...props }: ExtractChildrenProps): JSX.Element;
@@ -48,18 +48,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
49
  };
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
- var classnames_1 = __importDefault(require("classnames"));
52
51
  var react_1 = __importStar(require("react"));
52
+ var cloneStyledElement_1 = __importDefault(require("./utils/cloneStyledElement"));
53
53
  /**
54
54
  * Extracts all children of a parent component into its own component.
55
55
  */
56
56
  function ExtractChildren(_a) {
57
- var children = _a.children, className = _a.className, props = __rest(_a, ["children", "className"]);
58
- return (react_1.default.createElement(react_1.default.Fragment, null, react_1.Children.map(children, function (child, idx) {
57
+ var children = _a.children, props = __rest(_a, ["children"]);
58
+ return (react_1.default.createElement(react_1.default.Fragment, null, react_1.Children.map(children, function (child) {
59
59
  if ((0, react_1.isValidElement)(child)) {
60
- return (0, react_1.cloneElement)(child, __assign({ className: (0, classnames_1.default)(className, child.props.className) }, props));
60
+ return (0, cloneStyledElement_1.default)(child, __assign({}, props));
61
+ }
62
+ else {
63
+ return child;
61
64
  }
62
- return child;
63
65
  })));
64
66
  }
65
67
  exports.default = ExtractChildren;
@@ -1 +1 @@
1
- {"version":3,"file":"ExtractChildren.js","sourceRoot":"/","sources":["ExtractChildren.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAqF;AAIrF;;GAEG;AACH,SAAwB,eAAe,CAAC,EAIhC;IAHN,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACN,KAAK,cAH8B,yBAIvC,CADS;IAER,OAAO,CACL,8DACG,gBAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAC,KAAK,EAAE,GAAG;QACjC,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,oBAAY,EAAC,KAAK,aAAI,SAAS,EAAE,IAAA,oBAAU,EAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,IAAK,KAAK,EAAG,CAAA;SAClG;QAED,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CACD,CACJ,CAAA;AACH,CAAC;AAhBD,kCAgBC","sourcesContent":["import classNames from 'classnames'\nimport React, { Children, cloneElement, HTMLAttributes, isValidElement } from 'react'\n\nexport type Props = HTMLAttributes<HTMLElement>\n\n/**\n * Extracts all children of a parent component into its own component.\n */\nexport default function ExtractChildren({\n children,\n className,\n ...props\n}: Props) {\n return (\n <>\n {Children.map(children, (child, idx) => {\n if (isValidElement(child)) {\n return cloneElement(child, { className: classNames(className, child.props.className), ...props })\n }\n\n return child\n })}\n </>\n )\n}\n"]}
1
+ {"version":3,"file":"ExtractChildren.js","sourceRoot":"/","sources":["ExtractChildren.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAuE;AACvE,kFAA2D;AAI3D;;GAEG;AACH,SAAwB,eAAe,CAAC,EAGjB;IAFrB,IAAA,QAAQ,cAAA,EACL,KAAK,cAF8B,YAGvC,CADS;IAER,OAAO,CACL,8DACG,gBAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAA,KAAK;QAC3B,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,4BAAkB,EAAC,KAAK,eAAO,KAAK,EAAG,CAAA;SAC/C;aACI;YACH,OAAO,KAAK,CAAA;SACb;IACH,CAAC,CAAC,CACD,CACJ,CAAA;AACH,CAAC;AAhBD,kCAgBC","sourcesContent":["import React, { Children, HTMLAttributes, isValidElement } from 'react'\nimport cloneStyledElement from './utils/cloneStyledElement'\n\nexport type ExtractChildrenProps = HTMLAttributes<HTMLElement>\n\n/**\n * Extracts all children of a parent component into its own component.\n */\nexport default function ExtractChildren({\n children,\n ...props\n}: ExtractChildrenProps) {\n return (\n <>\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneStyledElement(child, { ...props })\n }\n else {\n return child\n }\n })}\n </>\n )\n}\n"]}
package/lib/FlatSVG.d.ts CHANGED
@@ -1,67 +1,72 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type Props = HTMLAttributes<HTMLDivElement> & {
2
+ export type FlatSVGProps = HTMLAttributes<HTMLDivElement> & {
3
3
  /**
4
4
  * The SVG string markup, i.e. "<svg>...</svg>".
5
5
  */
6
- markup: string;
6
+ svg: string;
7
7
  /**
8
- * Specifies whether the 'class' should be removed in the SVG root node and all of its child
9
- * nodes.
8
+ * Specifies whether the 'class' should be removed in the SVG root node and
9
+ * all of its child nodes.
10
10
  */
11
11
  stripClasses?: boolean;
12
12
  /**
13
- * Specifies whether extraneous attributes should be removed from the SVG root node. The
14
- * `whitelistedAttributes` prop defines what attributes should be kept.
13
+ * Specifies whether extraneous attributes should be removed from the SVG root
14
+ * node. The `whitelistedAttributes` prop defines what attributes should be
15
+ * kept.
15
16
  */
16
17
  stripExtraneousAttributes?: boolean;
17
18
  /**
18
- * Specifies whether the 'id' attribute should be removed in the SVG root node and all of its
19
- * child nodes.
19
+ * Specifies whether the 'id' attribute should be removed in the SVG root node
20
+ * and all of its child nodes.
20
21
  */
21
22
  stripIds?: boolean;
22
23
  /**
23
- * Specifies whether the 'style' atribute and any <style> nodes should be removed in the SVG root
24
- * node and all of its child nodes.
24
+ * Specifies whether the 'style' atribute and any <style> nodes should be
25
+ * removed in the SVG root node and all of its child nodes.
25
26
  */
26
27
  stripStyles?: boolean;
27
28
  /**
28
- * Specifies attribute names to exclude from being stripped if `stripExtraneousAttributes` is
29
- * enabled. By default, only `viewBox` is whitelisted.
29
+ * Specifies attribute names to exclude from being stripped if
30
+ * `stripExtraneousAttributes` is enabled. By default, only `viewBox` is
31
+ * whitelisted.
30
32
  */
31
33
  whitelistedAttributes?: string[];
32
34
  };
33
35
  /**
34
- * A component whose root element wraps an SVG markup. When wrapping the SVG, it will attempt to
35
- * sanitize the markup (i.e. stripping useless attributes) according to the props specified.
36
+ * A component whose root element wraps an SVG markup. When wrapping the SVG, it
37
+ * will attempt to sanitize the markup (i.e. stripping useless attributes)
38
+ * according to the props specified.
36
39
  */
37
40
  declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
38
41
  /**
39
42
  * The SVG string markup, i.e. "<svg>...</svg>".
40
43
  */
41
- markup: string;
44
+ svg: string;
42
45
  /**
43
- * Specifies whether the 'class' should be removed in the SVG root node and all of its child
44
- * nodes.
46
+ * Specifies whether the 'class' should be removed in the SVG root node and
47
+ * all of its child nodes.
45
48
  */
46
49
  stripClasses?: boolean | undefined;
47
50
  /**
48
- * Specifies whether extraneous attributes should be removed from the SVG root node. The
49
- * `whitelistedAttributes` prop defines what attributes should be kept.
51
+ * Specifies whether extraneous attributes should be removed from the SVG root
52
+ * node. The `whitelistedAttributes` prop defines what attributes should be
53
+ * kept.
50
54
  */
51
55
  stripExtraneousAttributes?: boolean | undefined;
52
56
  /**
53
- * Specifies whether the 'id' attribute should be removed in the SVG root node and all of its
54
- * child nodes.
57
+ * Specifies whether the 'id' attribute should be removed in the SVG root node
58
+ * and all of its child nodes.
55
59
  */
56
60
  stripIds?: boolean | undefined;
57
61
  /**
58
- * Specifies whether the 'style' atribute and any <style> nodes should be removed in the SVG root
59
- * node and all of its child nodes.
62
+ * Specifies whether the 'style' atribute and any <style> nodes should be
63
+ * removed in the SVG root node and all of its child nodes.
60
64
  */
61
65
  stripStyles?: boolean | undefined;
62
66
  /**
63
- * Specifies attribute names to exclude from being stripped if `stripExtraneousAttributes` is
64
- * enabled. By default, only `viewBox` is whitelisted.
67
+ * Specifies attribute names to exclude from being stripped if
68
+ * `stripExtraneousAttributes` is enabled. By default, only `viewBox` is
69
+ * whitelisted.
65
70
  */
66
71
  whitelistedAttributes?: string[] | undefined;
67
72
  } & React.RefAttributes<HTMLDivElement>>;
package/lib/FlatSVG.js CHANGED
@@ -1,8 +1,4 @@
1
1
  "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
2
  var __assign = (this && this.__assign) || function () {
7
3
  __assign = Object.assign || function(t) {
8
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -73,12 +69,36 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
69
  }
74
70
  return to.concat(ar || Array.prototype.slice.call(from));
75
71
  };
76
- var __importDefault = (this && this.__importDefault) || function (mod) {
77
- return (mod && mod.__esModule) ? mod : { "default": mod };
78
- };
79
72
  Object.defineProperty(exports, "__esModule", { value: true });
80
73
  var react_1 = __importStar(require("react"));
81
- var styled_components_1 = __importDefault(require("styled-components"));
74
+ /**
75
+ * A component whose root element wraps an SVG markup. When wrapping the SVG, it
76
+ * will attempt to sanitize the markup (i.e. stripping useless attributes)
77
+ * according to the props specified.
78
+ */
79
+ exports.default = (0, react_1.forwardRef)(function (_a, ref) {
80
+ var svg = _a.svg, _b = _a.stripClasses, stripClasses = _b === void 0 ? true : _b, _c = _a.stripExtraneousAttributes, stripExtraneousAttributes = _c === void 0 ? true : _c, _d = _a.stripIds, stripIds = _d === void 0 ? true : _d, _e = _a.stripStyles, stripStyles = _e === void 0 ? true : _e, _f = _a.whitelistedAttributes, whitelistedAttributes = _f === void 0 ? ['viewBox'] : _f, props = __rest(_a, ["svg", "stripClasses", "stripExtraneousAttributes", "stripIds", "stripStyles", "whitelistedAttributes"]);
81
+ var sanitizedMarkup = function () {
82
+ var mockContainer = document.createElement('div');
83
+ mockContainer.innerHTML = svg;
84
+ var elements = mockContainer.getElementsByTagName('svg');
85
+ if (elements.length > 1)
86
+ throw new Error('More than one SVG element found in provided markup');
87
+ var svgElement = elements[0];
88
+ if (!svgElement)
89
+ throw new Error('No SVG in provided markup');
90
+ if (stripExtraneousAttributes)
91
+ removeAttributes(svgElement, undefined, false, __spreadArray(__spreadArray([], __read(whitelistedAttributes), false), ['style', 'class', 'id'], false));
92
+ if (stripIds)
93
+ removeAttributes(svgElement, ['id'], true);
94
+ if (stripClasses)
95
+ removeAttributes(svgElement, ['class'], true);
96
+ if (stripStyles)
97
+ removeStyles(svgElement);
98
+ return svgElement.outerHTML;
99
+ };
100
+ return (react_1.default.createElement("figure", __assign({}, props, { ref: ref, dangerouslySetInnerHTML: { __html: sanitizedMarkup() } })));
101
+ });
82
102
  function removeStyles(element) {
83
103
  element.removeAttribute('style');
84
104
  var inlineStyles = element.getElementsByTagName('style');
@@ -111,33 +131,4 @@ function removeAttributes(element, attributes, recursive, whitelist) {
111
131
  }
112
132
  }
113
133
  }
114
- /**
115
- * A component whose root element wraps an SVG markup. When wrapping the SVG, it will attempt to
116
- * sanitize the markup (i.e. stripping useless attributes) according to the props specified.
117
- */
118
- exports.default = (0, react_1.forwardRef)(function (_a, ref) {
119
- var markup = _a.markup, _b = _a.stripClasses, stripClasses = _b === void 0 ? true : _b, _c = _a.stripExtraneousAttributes, stripExtraneousAttributes = _c === void 0 ? true : _c, _d = _a.stripIds, stripIds = _d === void 0 ? true : _d, _e = _a.stripStyles, stripStyles = _e === void 0 ? true : _e, _f = _a.whitelistedAttributes, whitelistedAttributes = _f === void 0 ? ['viewBox'] : _f, props = __rest(_a, ["markup", "stripClasses", "stripExtraneousAttributes", "stripIds", "stripStyles", "whitelistedAttributes"]);
120
- function sanitizedMarkup() {
121
- var mockContainer = document.createElement('div');
122
- mockContainer.innerHTML = markup;
123
- var elements = mockContainer.getElementsByTagName('svg');
124
- if (elements.length > 1)
125
- throw new Error('More than one SVG element found in provided markup');
126
- var svgElement = elements[0];
127
- if (!svgElement)
128
- throw new Error('No SVG in provided markup');
129
- if (stripExtraneousAttributes)
130
- removeAttributes(svgElement, undefined, false, __spreadArray(__spreadArray([], __read(whitelistedAttributes), false), ['style', 'class', 'id'], false));
131
- if (stripIds)
132
- removeAttributes(svgElement, ['id'], true);
133
- if (stripClasses)
134
- removeAttributes(svgElement, ['class'], true);
135
- if (stripStyles)
136
- removeStyles(svgElement);
137
- return svgElement.outerHTML;
138
- }
139
- return (react_1.default.createElement(StyledRoot, __assign({ ref: ref, dangerouslySetInnerHTML: { __html: sanitizedMarkup() } }, props)));
140
- });
141
- var StyledRoot = styled_components_1.default.figure(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n box-sizing: border-box;\n display: inline-block;\n flex: 0 0 auto;\n height: auto;\n position: relative;\n width: auto;\n\n svg {\n height: auto;\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n width: auto;\n\n * {\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n }\n }\n"], ["\n box-sizing: border-box;\n display: inline-block;\n flex: 0 0 auto;\n height: auto;\n position: relative;\n width: auto;\n\n svg {\n height: auto;\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n width: auto;\n\n * {\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n }\n }\n"])));
142
- var templateObject_1;
143
134
  //# sourceMappingURL=FlatSVG.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FlatSVG.js","sourceRoot":"/","sources":["FlatSVG.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyD;AACzD,wEAAsC;AAuCtC,SAAS,YAAY,CAAC,OAAgB;IACpC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IAEhC,IAAM,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAA;IAC1D,IAAM,eAAe,GAAG,YAAY,CAAC,MAAM,CAAA;IAE3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,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AAA;IAC7B,CAAC;IAED,OAAO,CACL,8BAAC,UAAU,aACT,GAAG,EAAE,GAAG,EACR,uBAAuB,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,IAClD,KAAK,EACT,CACH,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,IAAM,UAAU,GAAG,2BAAM,CAAC,MAAM,sjBAAA,mfAuB/B,IAAA,CAAA","sourcesContent":["import React, { forwardRef, HTMLAttributes } from 'react'\nimport styled from 'styled-components'\n\nexport type Props = HTMLAttributes<HTMLDivElement> & {\n /**\n * The SVG string markup, i.e. \"<svg>...</svg>\".\n */\n markup: string\n\n /**\n * Specifies whether the 'class' should be removed in the SVG root node and all of its child\n * nodes.\n */\n stripClasses?: boolean\n\n /**\n * Specifies whether extraneous attributes should be removed from the SVG root node. The\n * `whitelistedAttributes` prop defines what attributes should be kept.\n */\n stripExtraneousAttributes?: boolean\n\n /**\n * Specifies whether the 'id' attribute should be removed in the SVG root node and all of its\n * child nodes.\n */\n stripIds?: boolean\n\n /**\n * Specifies whether the 'style' atribute and any <style> nodes should be removed in the SVG root\n * node and all of its child nodes.\n */\n stripStyles?: boolean\n\n /**\n * Specifies attribute names to exclude from being stripped if `stripExtraneousAttributes` is\n * enabled. By default, only `viewBox` is whitelisted.\n */\n whitelistedAttributes?: string[]\n}\n\nfunction removeStyles(element: Element) {\n element.removeAttribute('style')\n\n const inlineStyles = element.getElementsByTagName('style')\n const numInlineStyles = inlineStyles.length\n\n for (let i = 0; i < numInlineStyles; i++) {\n const inlineStyle = inlineStyles[i]\n inlineStyle.remove()\n }\n\n const numChildren = element.children.length\n\n for (let i = 0; i < numChildren; i++) {\n removeStyles(element.children[i])\n }\n}\n\nfunction removeAttributes(element: Element, attributes: string[] | undefined = undefined, recursive = false, whitelist: string[] = []) {\n const attrs = attributes ?? element.getAttributeNames()\n const numAttrs = attrs.length\n\n for (let i = 0; i < numAttrs; i++) {\n const attr = attrs[i]\n const keep = whitelist.indexOf(attr) > -1\n if (!keep) element.removeAttribute(attr)\n }\n\n if (recursive) {\n const numChildren = element.children.length\n\n for (let i = 0; i < numChildren; i++) {\n removeAttributes(element.children[i], attributes, recursive, whitelist)\n }\n }\n}\n\n/**\n * A component whose root element wraps an SVG markup. When wrapping the SVG, it will attempt to\n * sanitize the markup (i.e. stripping useless attributes) according to the props specified.\n */\nexport default forwardRef<HTMLDivElement, Props>(({\n markup,\n stripClasses = true,\n stripExtraneousAttributes = true,\n stripIds = true,\n stripStyles = true,\n whitelistedAttributes = ['viewBox'],\n ...props\n}, ref) => {\n function sanitizedMarkup(): string {\n const mockContainer = document.createElement('div')\n mockContainer.innerHTML = markup\n\n const elements = mockContainer.getElementsByTagName('svg')\n if (elements.length > 1) throw new Error('More than one SVG element found in provided markup')\n\n const svgElement = elements[0]\n if (!svgElement) throw new Error('No SVG in provided markup')\n\n if (stripExtraneousAttributes) removeAttributes(svgElement, undefined, false, [...whitelistedAttributes, 'style', 'class', 'id'])\n if (stripIds) removeAttributes(svgElement, ['id'], true)\n if (stripClasses) removeAttributes(svgElement, ['class'], true)\n if (stripStyles) removeStyles(svgElement)\n\n return svgElement.outerHTML\n }\n\n return (\n <StyledRoot\n ref={ref}\n dangerouslySetInnerHTML={{ __html: sanitizedMarkup() }}\n {...props}\n />\n )\n})\n\nconst StyledRoot = styled.figure`\n box-sizing: border-box;\n display: inline-block;\n flex: 0 0 auto;\n height: auto;\n position: relative;\n width: auto;\n\n svg {\n height: auto;\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n width: auto;\n\n * {\n transition-delay: inherit;\n transition-duration: inherit;\n transition-property: inherit;\n transition-timing-function: inherit;\n }\n }\n`\n"]}
1
+ {"version":3,"file":"FlatSVG.js","sourceRoot":"/","sources":["FlatSVG.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyD;A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AAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;KACzC;IAED,IAAI,SAAS,EAAE;QACb,IAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAA;QAE3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE;YACpC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;SACxE;KACF;AACH,CAAC","sourcesContent":["import React, { forwardRef, HTMLAttributes } from 'react'\n\nexport type FlatSVGProps = HTMLAttributes<HTMLDivElement> & {\n /**\n * The SVG string markup, i.e. \"<svg>...</svg>\".\n */\n svg: string\n\n /**\n * Specifies whether the 'class' should be removed in the SVG root node and\n * all of its child nodes.\n */\n stripClasses?: boolean\n\n /**\n * Specifies whether extraneous attributes should be removed from the SVG root\n * node. The `whitelistedAttributes` prop defines what attributes should be\n * kept.\n */\n stripExtraneousAttributes?: boolean\n\n /**\n * Specifies whether the 'id' attribute should be removed in the SVG root node\n * and all of its child nodes.\n */\n stripIds?: boolean\n\n /**\n * Specifies whether the 'style' atribute and any <style> nodes should be\n * removed in the SVG root node and all of its child nodes.\n */\n stripStyles?: boolean\n\n /**\n * Specifies attribute names to exclude from being stripped if\n * `stripExtraneousAttributes` is enabled. By default, only `viewBox` is\n * whitelisted.\n */\n whitelistedAttributes?: string[]\n}\n\n/**\n * A component whose root element wraps an SVG markup. When wrapping the SVG, it\n * will attempt to sanitize the markup (i.e. stripping useless attributes)\n * according to the props specified.\n */\nexport default forwardRef<HTMLDivElement, FlatSVGProps>(({\n svg,\n stripClasses = true,\n stripExtraneousAttributes = true,\n stripIds = true,\n stripStyles = true,\n whitelistedAttributes = ['viewBox'],\n ...props\n}, ref) => {\n const sanitizedMarkup = () => {\n const mockContainer = document.createElement('div')\n mockContainer.innerHTML = svg\n\n const elements = mockContainer.getElementsByTagName('svg')\n if (elements.length > 1) throw new Error('More than one SVG element found in provided markup')\n\n const svgElement = elements[0]\n if (!svgElement) throw new Error('No SVG in provided markup')\n\n if (stripExtraneousAttributes) removeAttributes(svgElement, undefined, false, [...whitelistedAttributes, 'style', 'class', 'id'])\n if (stripIds) removeAttributes(svgElement, ['id'], true)\n if (stripClasses) removeAttributes(svgElement, ['class'], true)\n if (stripStyles) removeStyles(svgElement)\n\n return svgElement.outerHTML\n }\n\n return (\n <figure\n {...props}\n ref={ref}\n dangerouslySetInnerHTML={{ __html: sanitizedMarkup() }}\n />\n )\n})\n\nfunction removeStyles(element: Element) {\n element.removeAttribute('style')\n\n const inlineStyles = element.getElementsByTagName('style')\n const numInlineStyles = inlineStyles.length\n\n for (let i = 0; i < numInlineStyles; i++) {\n const inlineStyle = inlineStyles[i]\n inlineStyle.remove()\n }\n\n const numChildren = element.children.length\n\n for (let i = 0; i < numChildren; i++) {\n removeStyles(element.children[i])\n }\n}\n\nfunction removeAttributes(element: Element, attributes: string[] | undefined = undefined, recursive = false, whitelist: string[] = []) {\n const attrs = attributes ?? element.getAttributeNames()\n const numAttrs = attrs.length\n\n for (let i = 0; i < numAttrs; i++) {\n const attr = attrs[i]\n const keep = whitelist.indexOf(attr) > -1\n if (!keep) element.removeAttribute(attr)\n }\n\n if (recursive) {\n const numChildren = element.children.length\n\n for (let i = 0; i < numChildren; i++) {\n removeAttributes(element.children[i], attributes, recursive, whitelist)\n }\n }\n}\n"]}