@helsenorge/designsystem-react 12.3.0 → 12.5.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 (88) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/Checkbox.js +2 -4
  3. package/Checkbox.js.map +1 -1
  4. package/Drawer.js +33 -8
  5. package/Drawer.js.map +1 -1
  6. package/ElementHeader.js +5 -4
  7. package/ElementHeader.js.map +1 -1
  8. package/FormGroup.js +8 -3
  9. package/FormGroup.js.map +1 -1
  10. package/HelpTriggerIcon.js +13 -2
  11. package/HelpTriggerIcon.js.map +1 -1
  12. package/Input.js +2 -3
  13. package/Input.js.map +1 -1
  14. package/LazyIcon.js +1 -1
  15. package/LazyIcon.js.map +1 -1
  16. package/LinkList.js +81 -47
  17. package/LinkList.js.map +1 -1
  18. package/ListEditMode.js +42 -0
  19. package/ListEditMode.js.map +1 -0
  20. package/PanelOld.js.map +1 -1
  21. package/RadioButton.js +1 -1
  22. package/RadioButton.js.map +1 -1
  23. package/Select.js +1 -1
  24. package/Select.js.map +1 -1
  25. package/components/Drawer/Drawer.d.ts +6 -1
  26. package/components/Drawer/resourceHelper.d.ts +3 -0
  27. package/components/ElementHeader/styles.module.scss +7 -9
  28. package/components/ElementHeader/styles.module.scss.d.ts +2 -1
  29. package/components/ExpanderList/ExpanderList.d.ts +8 -1
  30. package/components/ExpanderList/index.js +51 -20
  31. package/components/ExpanderList/index.js.map +1 -1
  32. package/components/ExpanderList/styles.module.scss +37 -33
  33. package/components/FavoriteButton/FavoriteButton.d.ts +19 -0
  34. package/components/FavoriteButton/FavoriteButton.test.d.ts +1 -0
  35. package/components/FavoriteButton/StarIcon.d.ts +4 -0
  36. package/components/FavoriteButton/index.d.ts +3 -0
  37. package/components/FavoriteButton/index.js +209 -0
  38. package/components/FavoriteButton/index.js.map +1 -0
  39. package/components/FavoriteButton/resourceHelper.d.ts +3 -0
  40. package/components/FavoriteButton/stories.module.scss +22 -0
  41. package/components/FavoriteButton/stories.module.scss.d.ts +10 -0
  42. package/components/FavoriteButton/styles.module.scss +48 -0
  43. package/components/FavoriteButton/styles.module.scss.d.ts +10 -0
  44. package/components/FormGroup/FormGroup.d.ts +2 -0
  45. package/components/HelpTriggerIcon/HelpTriggerIcon.d.ts +2 -0
  46. package/components/HelpTriggerIcon/styles.module.scss +22 -1
  47. package/components/Icons/AdditionalIconInformation.d.ts +4 -0
  48. package/components/Icons/AdditionalIconInformation.js +2 -1
  49. package/components/Icons/AdditionalIconInformation.js.map +1 -1
  50. package/components/Icons/Feedback.d.ts +4 -0
  51. package/components/Icons/Feedback.js +25 -0
  52. package/components/Icons/Feedback.js.map +1 -0
  53. package/components/Icons/IconNames.d.ts +1 -1
  54. package/components/Icons/IconNames.js +1 -0
  55. package/components/Icons/IconNames.js.map +1 -1
  56. package/components/LinkList/LinkList.d.ts +8 -1
  57. package/components/LinkList/index.js +2 -0
  58. package/components/LinkList/index.js.map +1 -1
  59. package/components/LinkList/styles.module.scss +30 -22
  60. package/components/List/stories.module.scss +7 -0
  61. package/components/List/stories.module.scss.d.ts +9 -0
  62. package/components/ListEditMode/ListEditMode.d.ts +29 -0
  63. package/components/ListEditMode/index.d.ts +3 -0
  64. package/components/ListEditMode/index.js +9 -0
  65. package/components/ListEditMode/index.js.map +1 -0
  66. package/components/ListEditMode/styles.module.scss +79 -0
  67. package/components/ListEditMode/styles.module.scss.d.ts +18 -0
  68. package/components/Panel/styles.module.scss +5 -2
  69. package/components/PopMenu/index.js +1 -1
  70. package/components/PopMenu/index.js.map +1 -1
  71. package/components/PopMenu/styles.module.scss +4 -0
  72. package/components/PopMenu/styles.module.scss.d.ts +1 -0
  73. package/components/RadioButton/styles.module.scss +22 -4
  74. package/components/StatusDot/styles.module.scss +6 -0
  75. package/components/Tabs/Tabs.d.ts +6 -3
  76. package/components/Tabs/index.js +38 -4
  77. package/components/Tabs/index.js.map +1 -1
  78. package/components/Tabs/resourceHelper.d.ts +3 -0
  79. package/constants.d.ts +1 -0
  80. package/constants.js +1 -0
  81. package/constants.js.map +1 -1
  82. package/package.json +1 -1
  83. package/resources/HN.Designsystem.Drawer.en-GB.json.d.ts +6 -0
  84. package/resources/HN.Designsystem.Drawer.nb-NO.json.d.ts +6 -0
  85. package/resources/HN.Designsystem.FavoriteButton.nb-NO.json.d.ts +6 -0
  86. package/resources/HN.Designsystem.Tabs.en-GB.json.d.ts +7 -0
  87. package/resources/HN.Designsystem.Tabs.nb-NO.json.d.ts +7 -0
  88. package/components/Tabs/TabsDocs.d.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/ExpanderList/ExpanderList.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { useExpand } from '../../hooks/useExpand';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { useUuid } from '../../hooks/useUuid';\nimport { PaletteNames } from '../../theme/palette';\nimport { mergeRefs } from '../../utils/refs';\nimport { isElementInViewport } from '../../utils/viewport';\nimport { ElementHeaderType, renderElementHeader } from '../ElementHeader/ElementHeader';\nimport Highlighter from '../Highlighter';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { TitleTags } from '../Title';\n\nimport expanderListStyles from './styles.module.scss';\n\nexport type ExpanderListColors = Extract<PaletteNames, 'white' | 'blueberry' | 'cherry' | 'neutral'>;\nexport interface ExpanderType extends React.ForwardRefExoticComponent<ExpanderProps & React.RefAttributes<HTMLLIElement>> {\n ElementHeader?: ElementHeaderType;\n}\n\nexport interface ExpanderListCompound extends React.ForwardRefExoticComponent<ExpanderListProps & React.RefAttributes<HTMLUListElement>> {\n Expander: ExpanderType;\n}\n\nexport type ExpanderListVariant = 'line' | 'outline' | 'fill' | 'fill-negative';\n\nexport type ExpanderListStatus = 'none' | 'new';\n\ninterface ExpanderListProps {\n /** Toggles accordion functionality for the expanders. */\n accordion?: boolean;\n /** Items in the ExpanderList */\n children: React.ReactNode;\n /** Toggles padding of child elements */\n childPadding?: boolean;\n /** Adds custom classes to the element. */\n className?: string;\n /** Changes the colors of the list. */\n color?: ExpanderListColors;\n /** Changes the font size. */\n large?: boolean;\n /** Whether to render children when closed (in which case they are hidden with CSS). Default: false */\n renderChildrenWhenClosed?: boolean;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets visual priority */\n variant?: ExpanderListVariant;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n /** Highlights text in title and content. Used for search results */\n highlightText?: string;\n}\n\ntype Modify<T, R> = Omit<T, keyof R> & R;\n\ntype ExpanderProps = Modify<\n React.HTMLAttributes<HTMLButtonElement>,\n {\n id?: string;\n title: JSX.Element | string;\n /** Changes the underlying element of the title. Default: span*/\n titleHtmlMarkup?: TitleTags;\n children: React.ReactNode;\n className?: string;\n color?: ExpanderListColors;\n icon?: React.ReactElement;\n padding?: boolean;\n expanded?: boolean;\n large?: boolean;\n testId?: string;\n handleExpanderClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n /** Highlights text in title and content. Override if different from list. */\n highlightText?: string;\n /** Displays a status on the left side: default none */\n status?: ExpanderListStatus;\n }\n> &\n Pick<ExpanderListProps, 'renderChildrenWhenClosed' | 'variant'>;\n\nconst Expander: ExpanderType = React.forwardRef<HTMLLIElement, ExpanderProps>((props, ref) => {\n const {\n id,\n children,\n padding = true,\n color = 'neutral',\n className = '',\n icon,\n large = false,\n title,\n titleHtmlMarkup = 'span',\n expanded = false,\n testId,\n handleExpanderClick,\n onExpand,\n renderChildrenWhenClosed,\n variant = 'line',\n zIndex = 0,\n highlightText,\n status = 'none',\n } = props;\n const [isExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLLIElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered, isFocused } = usePseudoClasses(triggerRef);\n\n const isFill = variant === 'fill';\n const isFillNegative = variant === 'fill-negative';\n const isOutline = variant === 'outline';\n const isLine = variant === 'line';\n\n const itemClasses = classNames(className, expanderListStyles['expander-list__item'], {\n [expanderListStyles[`expander-list__item--fill`]]: isFill,\n [expanderListStyles[`expander-list__item--fill--${color}`]]: isFill,\n [expanderListStyles[`expander-list__item--fill-negative`]]: isFillNegative,\n [expanderListStyles[`expander-list__item--fill-negative--${color}`]]: isFillNegative,\n [expanderListStyles['expander-list__item--outline']]: isOutline,\n [expanderListStyles[`expander-list__item--outline--${color}`]]: isOutline,\n [expanderListStyles['expander-list__item--line']]: isLine,\n [expanderListStyles[`expander-list__item--line--${color}`]]: isLine,\n [expanderListStyles[`expander-list__item--new`]]: status === 'new',\n });\n\n const expanderClasses = classNames(expanderListStyles['expander-list-link'], expanderListStyles[`expander-list-link--${color}`], {\n [expanderListStyles[`expander-list-link--fill--${color}`]]: isFill,\n [expanderListStyles[`expander-list-link--fill-negative`]]: isFillNegative,\n [expanderListStyles[`expander-list-link--fill-negative--${color}`]]: isFillNegative,\n [expanderListStyles['expander-list-link--outline']]: isOutline,\n [expanderListStyles[`expander-list-link--outline--${color}`]]: isOutline,\n [expanderListStyles[`expander-list-link--line--${color}`]]: isLine,\n [expanderListStyles['expander-list-link--open']]: isExpanded,\n [expanderListStyles['expander-list-link--large']]: large,\n [expanderListStyles[`expander-list-link--new`]]: status === 'new',\n });\n\n const renderContent = (): React.ReactNode => {\n if (!renderChildrenWhenClosed && !isExpanded) {\n return null;\n }\n\n const mainContentClasses = classNames(expanderListStyles['expander-list-link__main-content'], {\n [expanderListStyles['expander-list-link__main-content--expanded']]: isExpanded,\n [expanderListStyles['expander-list-link__main-content--padding']]: padding,\n [expanderListStyles[`expander-list-link__main-content--outline--${color}`]]: isOutline,\n [expanderListStyles[`expander-list-link__main-content--new`]]: status === 'new',\n });\n\n return (\n <div className={mainContentClasses} data-state={isExpanded ? 'open' : 'closed'}>\n <Highlighter searchText={highlightText}>{children}</Highlighter>\n </div>\n );\n };\n\n const statusMarkerClasses = classNames(expanderListStyles['expander-list__item__status-marker'], {\n [expanderListStyles['expander-list__item__status-marker--new']]: status === 'new',\n });\n\n return (\n <li className={itemClasses} ref={mergeRefs([ref, expanderRef])}>\n {status !== 'none' && <div className={statusMarkerClasses}></div>}\n <button\n type=\"button\"\n id={id}\n onClick={handleExpanderClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.ExpanderListExpander}\n className={expanderClasses}\n ref={triggerRef}\n aria-expanded={isExpanded}\n style={{\n zIndex: isFocused ? zIndex + 1 : zIndex,\n }}\n >\n {renderElementHeader(title, {\n titleHtmlMarkup,\n isHovered: isHovered || isFocused,\n size: large ? 'large' : 'medium',\n parentType: 'expanderlist',\n chevronIcon: isExpanded ? ChevronUp : ChevronDown,\n icon,\n highlightText,\n })}\n </button>\n {renderContent()}\n </li>\n );\n});\n\ntype ActiveExpander = Record<string, boolean>;\n\nconst isExpanderComponent = (element: unknown | null | undefined): element is React.ReactElement<ExpanderProps> =>\n React.isValidElement<ExpanderProps>(element) && (element as React.ReactElement).type === Expander;\n\nexport const ExpanderList = React.forwardRef((props: ExpanderListProps, ref: React.Ref<HTMLUListElement>) => {\n const {\n children,\n childPadding = true,\n large,\n renderChildrenWhenClosed = false,\n color = 'white',\n className = '',\n accordion = false,\n testId,\n variant,\n zIndex,\n highlightText,\n } = props;\n const [activeExpander, setActiveExpander] = useState<ActiveExpander>();\n const [latestExpander, setLatestExpander] = useState<HTMLElement>();\n const uuid = useUuid();\n const expanderListClasses = classNames(expanderListStyles['expander-list'], className, {\n [expanderListStyles[`expander-list--outline--${color}`]]: variant === 'outline',\n [expanderListStyles[`expander-list--fill`]]: variant === 'fill' || variant === 'fill-negative',\n });\n\n function handleExpanderClick(event: React.MouseEvent<HTMLElement, MouseEvent>, id: string): void {\n setActiveExpander(prevState => (accordion ? { [id]: !prevState?.[id] } : { ...prevState, [id]: !prevState?.[id] }));\n setLatestExpander(event.currentTarget);\n }\n\n const getExpanderId = (index: number): string => `${uuid}-${index}`;\n\n useEffect(() => {\n if (accordion && latestExpander && !isElementInViewport(latestExpander)) {\n latestExpander.scrollIntoView();\n }\n }, [accordion, latestExpander]);\n\n useEffect(() => {\n const newActiveExpander = React.Children.map(children, child => {\n if (isExpanderComponent(child)) {\n return child;\n }\n })?.reduce((acc, child, index) => {\n // Expanded-status skal bare settes dersom prop er satt av den som bruker komponenten\n if (typeof child.props.expanded !== 'undefined') {\n acc[getExpanderId(index)] = child.props.expanded;\n }\n return acc;\n }, {} as ActiveExpander);\n\n setActiveExpander({ ...activeExpander, ...newActiveExpander });\n }, [children]);\n\n return (\n <ul className={expanderListClasses} ref={ref} data-testid={testId} data-analyticsid={AnalyticsId.ExpanderList}>\n {React.Children.map(children, (child, index) => {\n if (isExpanderComponent(child)) {\n const id = getExpanderId(index);\n const expanded = activeExpander?.[id];\n const highlightTextChild: string | undefined = child.props.highlightText || highlightText;\n\n return React.cloneElement(child as React.ReactElement<ExpanderProps>, {\n id,\n key: index,\n expanded,\n padding: childPadding,\n color,\n large,\n 'aria-expanded': expanded,\n className: expanderListStyles['expander-list__item'],\n handleExpanderClick: (event: React.MouseEvent<HTMLElement>) => handleExpanderClick(event, `${uuid}-${index}`),\n renderChildrenWhenClosed,\n variant,\n zIndex: zIndex,\n highlightText: highlightTextChild,\n });\n }\n return child;\n })}\n </ul>\n );\n}) as ExpanderListCompound;\n\nExpanderList.displayName = 'ExpanderList';\nExpanderList.Expander = Expander;\nExpander.displayName = 'ExpanderList.Expander';\n\nexport default ExpanderList;\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;AAuFA,MAAM,WAAyBA,eAAM,WAAyC,CAAC,OAAO,QAAQ;AAC5F,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,IACR;AAAA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,aAAa,cAAc;AAC3B,aAAa,WAAW;AACxB,SAAS,cAAc;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/ExpanderList/ExpanderList.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId } from '../../constants';\nimport { useExpand } from '../../hooks/useExpand';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { useUuid } from '../../hooks/useUuid';\nimport { PaletteNames } from '../../theme/palette';\nimport { mergeRefs } from '../../utils/refs';\nimport { isElementInViewport } from '../../utils/viewport';\nimport { ElementHeaderType, renderElementHeader } from '../ElementHeader/ElementHeader';\nimport Highlighter from '../Highlighter';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport ListEditModeItem, { ListEditModeItemProps, listEditModeWrapperClassnames } from '../ListEditMode';\nimport { TitleTags } from '../Title';\n\nimport expanderListStyles from './styles.module.scss';\n\nexport type ExpanderListColors = Extract<PaletteNames, 'white' | 'blueberry' | 'cherry' | 'neutral'>;\nexport interface ExpanderType extends React.ForwardRefExoticComponent<ExpanderProps & React.RefAttributes<HTMLLIElement>> {\n ElementHeader?: ElementHeaderType;\n}\n\nexport interface ExpanderListCompound extends React.ForwardRefExoticComponent<ExpanderListProps & React.RefAttributes<HTMLUListElement>> {\n Expander: ExpanderType;\n}\n\nexport type ExpanderListVariant = 'line' | 'outline' | 'fill' | 'fill-negative';\n\nexport type ExpanderListStatus = 'none' | 'new';\n\ninterface ExpanderListProps {\n /** Toggles accordion functionality for the expanders. */\n accordion?: boolean;\n /** Items in the ExpanderList */\n children: React.ReactNode;\n /** Toggles padding of child elements */\n childPadding?: boolean;\n /** Adds custom classes to the element. */\n className?: string;\n /** Changes the colors of the list. */\n color?: ExpanderListColors;\n /** Changes the font size. */\n large?: boolean;\n /** Whether to render children when closed (in which case they are hidden with CSS). Default: false */\n renderChildrenWhenClosed?: boolean;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets visual priority */\n variant?: ExpanderListVariant;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n /** Highlights text in title and content. Used for search results */\n highlightText?: string;\n /**\n * @experimental This prop is experimental and may change in the future.\n * Enables ListEditMode\n */\n editMode?: boolean;\n}\n\ntype Modify<T, R> = Omit<T, keyof R> & R;\n\ntype ExpanderProps = Modify<\n React.HTMLAttributes<HTMLButtonElement>,\n {\n id?: string;\n title: JSX.Element | string;\n /** Changes the underlying element of the title. Default: span*/\n titleHtmlMarkup?: TitleTags;\n children: React.ReactNode;\n className?: string;\n color?: ExpanderListColors;\n icon?: React.ReactElement;\n padding?: boolean;\n expanded?: boolean;\n large?: boolean;\n testId?: string;\n handleExpanderClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n /** Highlights text in title and content. Override if different from list. */\n highlightText?: string;\n /** Displays a status on the left side: default none */\n status?: ExpanderListStatus;\n }\n> &\n Pick<ExpanderListProps, 'renderChildrenWhenClosed' | 'variant'> &\n ListEditModeItemProps;\n\nexport const Expander: ExpanderType = React.forwardRef<HTMLLIElement, ExpanderProps>((props, ref) => {\n const {\n id,\n children,\n padding = true,\n color = 'neutral',\n className = '',\n icon,\n large = false,\n title,\n titleHtmlMarkup = 'span',\n expanded = false,\n testId,\n handleExpanderClick,\n onExpand,\n renderChildrenWhenClosed,\n variant = 'line',\n zIndex = 0,\n highlightText,\n status = 'none',\n editMode = false,\n } = props;\n const [isExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLLIElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered, isFocused } = usePseudoClasses(triggerRef);\n\n const isFill = variant === 'fill';\n const isFillNegative = variant === 'fill-negative';\n const isOutline = variant === 'outline';\n const isLine = variant === 'line';\n\n const itemClasses = classNames(className, expanderListStyles['expander-list__item'], {\n [expanderListStyles[`expander-list__item--fill`]]: isFill,\n [expanderListStyles[`expander-list__item--fill--${color}`]]: isFill,\n [expanderListStyles[`expander-list__item--fill-negative`]]: isFillNegative,\n [expanderListStyles[`expander-list__item--fill-negative--${color}`]]: isFillNegative,\n [expanderListStyles['expander-list__item--outline']]: isOutline,\n [expanderListStyles[`expander-list__item--outline--${color}`]]: isOutline,\n [expanderListStyles['expander-list__item--line']]: isLine,\n [expanderListStyles[`expander-list__item--line--${color}`]]: isLine,\n [expanderListStyles[`expander-list__item--new`]]: status === 'new',\n });\n\n const expanderClasses = classNames(expanderListStyles['expander-list-link'], expanderListStyles[`expander-list-link--${color}`], {\n [expanderListStyles[`expander-list-link--fill--${color}`]]: isFill,\n [expanderListStyles[`expander-list-link--fill-negative`]]: isFillNegative,\n [expanderListStyles[`expander-list-link--fill-negative--${color}`]]: isFillNegative,\n [expanderListStyles['expander-list-link--outline']]: isOutline,\n [expanderListStyles[`expander-list-link--outline--${color}`]]: isOutline,\n [expanderListStyles[`expander-list-link--line--${color}`]]: isLine,\n [expanderListStyles['expander-list-link--open']]: isExpanded,\n [expanderListStyles['expander-list-link--large']]: large,\n [expanderListStyles[`expander-list-link--new`]]: status === 'new',\n });\n\n const renderContent = (): React.ReactNode => {\n if (!renderChildrenWhenClosed && !isExpanded) {\n return null;\n }\n\n const mainContentClasses = classNames(expanderListStyles['expander-list-link__main-content'], {\n [expanderListStyles['expander-list-link__main-content--expanded']]: isExpanded,\n [expanderListStyles['expander-list-link__main-content--padding']]: padding,\n [expanderListStyles[`expander-list-link__main-content--outline--${color}`]]: isOutline,\n [expanderListStyles[`expander-list-link__main-content--new`]]: status === 'new',\n });\n\n return (\n <div className={mainContentClasses} data-state={isExpanded ? 'open' : 'closed'}>\n <Highlighter searchText={highlightText}>{children}</Highlighter>\n </div>\n );\n };\n\n const statusMarkerClasses = classNames(expanderListStyles['expander-list__item__status-marker'], {\n [expanderListStyles['expander-list__item__status-marker--new']]: status === 'new',\n });\n\n return (\n <li className={itemClasses} ref={mergeRefs([ref, expanderRef])}>\n {status !== 'none' && <div className={statusMarkerClasses}></div>}\n {editMode ? (\n <div id={id} data-testid={testId} data-analyticsid={AnalyticsId.ExpanderListExpander} className={expanderClasses}>\n {renderElementHeader(title, {\n titleHtmlMarkup,\n isHovered: false,\n size: large ? 'large' : 'medium',\n parentType: 'expanderlist',\n chevronIcon: undefined,\n icon,\n highlightText,\n })}\n </div>\n ) : (\n <button\n type=\"button\"\n id={id}\n onClick={handleExpanderClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.ExpanderListExpander}\n className={expanderClasses}\n ref={triggerRef}\n aria-expanded={isExpanded}\n style={{\n zIndex: isFocused ? zIndex + 1 : zIndex,\n }}\n >\n {renderElementHeader(title, {\n titleHtmlMarkup,\n isHovered: isHovered || isFocused,\n size: large ? 'large' : 'medium',\n parentType: 'expanderlist',\n chevronIcon: isExpanded ? ChevronUp : ChevronDown,\n icon,\n highlightText,\n })}\n </button>\n )}\n {!editMode && renderContent()}\n </li>\n );\n});\n\ntype ActiveExpander = Record<string, boolean>;\n\nconst isExpanderComponent = (element: unknown | null | undefined): element is React.ReactElement<ExpanderProps> =>\n React.isValidElement<ExpanderProps>(element) && (element as React.ReactElement).type === Expander;\n\nexport const ExpanderList = React.forwardRef((props: ExpanderListProps, ref: React.Ref<HTMLUListElement>) => {\n const {\n children,\n childPadding = true,\n large,\n renderChildrenWhenClosed = false,\n color = 'white',\n className = '',\n accordion = false,\n testId,\n variant,\n zIndex,\n highlightText,\n editMode = false,\n } = props;\n const [activeExpander, setActiveExpander] = useState<ActiveExpander>();\n const [latestExpander, setLatestExpander] = useState<HTMLElement>();\n const uuid = useUuid();\n const expanderListClasses = classNames(expanderListStyles['expander-list'], className, {\n [expanderListStyles[`expander-list--outline--${color}`]]: variant === 'outline',\n [expanderListStyles[`expander-list--fill`]]: variant === 'fill' || variant === 'fill-negative',\n [listEditModeWrapperClassnames]: editMode,\n });\n\n function handleExpanderClick(event: React.MouseEvent<HTMLElement, MouseEvent>, id: string): void {\n setActiveExpander(prevState => (accordion ? { [id]: !prevState?.[id] } : { ...prevState, [id]: !prevState?.[id] }));\n setLatestExpander(event.currentTarget);\n }\n\n const getExpanderId = (index: number): string => `${uuid}-${index}`;\n\n useEffect(() => {\n if (accordion && latestExpander && !isElementInViewport(latestExpander)) {\n latestExpander.scrollIntoView();\n }\n }, [accordion, latestExpander]);\n\n useEffect(() => {\n const newActiveExpander = React.Children.map(children, child => {\n if (isExpanderComponent(child)) {\n return child;\n }\n })?.reduce((acc, child, index) => {\n // Expanded-status skal bare settes dersom prop er satt av den som bruker komponenten\n if (typeof child.props.expanded !== 'undefined') {\n acc[getExpanderId(index)] = child.props.expanded;\n }\n return acc;\n }, {} as ActiveExpander);\n\n setActiveExpander({ ...activeExpander, ...newActiveExpander });\n }, [children]);\n\n return (\n <ul className={expanderListClasses} ref={ref} data-testid={testId} data-analyticsid={AnalyticsId.ExpanderList}>\n {React.Children.map(children, (child, index) => {\n if (isExpanderComponent(child)) {\n const id = getExpanderId(index);\n const expanded = activeExpander?.[id];\n const highlightTextChild: string | undefined = child.props.highlightText || highlightText;\n\n if (editMode) {\n return (\n <ListEditModeItem color={color} variant={variant} onDelete={child.props.onDelete}>\n {React.cloneElement(child, {\n id,\n key: index,\n expanded,\n padding: childPadding,\n color,\n large,\n 'aria-expanded': false,\n className: expanderListStyles['expander-list__item'],\n renderChildrenWhenClosed: false,\n variant,\n zIndex: zIndex,\n highlightText: highlightTextChild,\n editMode: true,\n })}\n </ListEditModeItem>\n );\n } else {\n return React.cloneElement(child as React.ReactElement<ExpanderProps>, {\n id,\n key: index,\n expanded,\n padding: childPadding,\n color,\n large,\n 'aria-expanded': expanded,\n className: expanderListStyles['expander-list__item'],\n handleExpanderClick: (event: React.MouseEvent<HTMLElement>) => handleExpanderClick(event, `${uuid}-${index}`),\n renderChildrenWhenClosed,\n variant,\n zIndex: zIndex,\n highlightText: highlightTextChild,\n });\n }\n }\n return child;\n })}\n </ul>\n );\n}) as ExpanderListCompound;\n\nExpanderList.displayName = 'ExpanderList';\nExpanderList.Expander = Expander;\nExpander.displayName = 'ExpanderList.Expander';\n\nexport default ExpanderList;\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;AA8FO,MAAM,WAAyBA,eAAM,WAAyC,CAAC,OAAO,QAAQ;AACnG,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,kBAAkB;AAAA,IAClB,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,SAAS;AAAA,IACT;AAAA,IACA,SAAS;AAAA,IACT,WAAW;AAAA,EAAA,IACT;AACJ,QAAM,CAAC,UAAU,IAAI,UAAU,UAAU,QAAQ;AACjD,QAAM,cAAc,OAAsB,IAAI;AAC9C,QAAM,aAAa,OAA0B,IAAI;AACjD,QAAM,EAAE,WAAW,cAAc,iBAAiB,UAAU;AAE5D,QAAM,SAAS,YAAY;AAC3B,QAAM,iBAAiB,YAAY;AACnC,QAAM,YAAY,YAAY;AAC9B,QAAM,SAAS,YAAY;AAE3B,QAAM,cAAc,WAAW,WAAW,mBAAmB,qBAAqB,GAAG;AAAA,IACnF,CAAC,mBAAmB,2BAA2B,CAAC,GAAG;AAAA,IACnD,CAAC,mBAAmB,8BAA8B,KAAK,EAAE,CAAC,GAAG;AAAA,IAC7D,CAAC,mBAAmB,oCAAoC,CAAC,GAAG;AAAA,IAC5D,CAAC,mBAAmB,uCAAuC,KAAK,EAAE,CAAC,GAAG;AAAA,IACtE,CAAC,mBAAmB,8BAA8B,CAAC,GAAG;AAAA,IACtD,CAAC,mBAAmB,iCAAiC,KAAK,EAAE,CAAC,GAAG;AAAA,IAChE,CAAC,mBAAmB,2BAA2B,CAAC,GAAG;AAAA,IACnD,CAAC,mBAAmB,8BAA8B,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AAAA,EAC/D,GAAG,CAAC,QAAQ,CAAC;AAEb,6BACG,MAAA,EAAG,WAAW,qBAAqB,KAAU,eAAa,QAAQ,oBAAkB,YAAY,cAC9F,yBAAM,SAAS,IAAI,UAAU,CAAC,OAAO,UAAU;AAC9C,QAAI,oBAAoB,KAAK,GAAG;AAC9B,YAAM,KAAK,cAAc,KAAK;AAC9B,YAAM,WAAW,iDAAiB;AAClC,YAAM,qBAAyC,MAAM,MAAM,iBAAiB;AAE5E,UAAI,UAAU;AACZ,eACE,oBAAC,kBAAA,EAAiB,OAAc,SAAkB,UAAU,MAAM,MAAM,UACrE,UAAAA,eAAM,aAAa,OAAO;AAAA,UACzB;AAAA,UACA,KAAK;AAAA,UACL;AAAA,UACA,SAAS;AAAA,UACT;AAAA,UACA;AAAA,UACA,iBAAiB;AAAA,UACjB,WAAW,mBAAmB,qBAAqB;AAAA,UACnD,0BAA0B;AAAA,UAC1B;AAAA,UACA;AAAA,UACA,eAAe;AAAA,UACf,UAAU;AAAA,QAAA,CACX,GACH;AAAA,MAEJ,OAAO;AACL,eAAOA,eAAM,aAAa,OAA4C;AAAA,UACpE;AAAA,UACA,KAAK;AAAA,UACL;AAAA,UACA,SAAS;AAAA,UACT;AAAA,UACA;AAAA,UACA,iBAAiB;AAAA,UACjB,WAAW,mBAAmB,qBAAqB;AAAA,UACnD,qBAAqB,CAAC,UAAyC,oBAAoB,OAAO,GAAG,IAAI,IAAI,KAAK,EAAE;AAAA,UAC5G;AAAA,UACA;AAAA,UACA;AAAA,UACA,eAAe;AAAA,QAAA,CAChB;AAAA,MACH;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC,EAAA,CACH;AAEJ,CAAC;AAED,aAAa,cAAc;AAC3B,aAAa,WAAW;AACxB,SAAS,cAAc;"}
@@ -187,7 +187,6 @@
187
187
  font-size: font-settings.$font-size-sm;
188
188
  line-height: font-settings.$lineheight-size-sm;
189
189
  display: flex;
190
- cursor: pointer;
191
190
  font-family: inherit;
192
191
  text-decoration: none;
193
192
  justify-content: space-between;
@@ -200,6 +199,10 @@
200
199
  grid-area: header;
201
200
  padding-left: var(--statusmarker-left-space);
202
201
 
202
+ &:not(div) {
203
+ cursor: pointer;
204
+ }
205
+
203
206
  @media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
204
207
  font-size: font-settings.$font-size-md;
205
208
  line-height: font-settings.$lineheight-size-md;
@@ -223,11 +226,12 @@
223
226
 
224
227
  &--white:not(.expander-list-link--outline, .expander-list-link--fill-negative) {
225
228
  &[aria-expanded='false'] {
226
- &:hover {
229
+ // expander settes til div om man er i edit mode, og skal da ikke ha hover/active effekter
230
+ &:hover:not(div) {
227
231
  background-color: var(--core-color-neutral-50);
228
232
  }
229
233
 
230
- &:active {
234
+ &:active:not(div) {
231
235
  background-color: var(--core-color-neutral-100);
232
236
  }
233
237
  }
@@ -235,11 +239,11 @@
235
239
  &[aria-expanded='true'] {
236
240
  background-color: var(--core-color-neutral-50);
237
241
 
238
- &:hover {
242
+ &:hover:not(div) {
239
243
  background-color: var(--core-color-neutral-100);
240
244
  }
241
245
 
242
- &:active {
246
+ &:active:not(div) {
243
247
  background-color: var(--core-color-neutral-200);
244
248
  }
245
249
  }
@@ -247,11 +251,11 @@
247
251
 
248
252
  &--blueberry:not(.expander-list-link--outline, .expander-list-link--fill-negative) {
249
253
  &[aria-expanded='false'] {
250
- &:hover {
254
+ &:hover:not(div) {
251
255
  background-color: var(--core-color-blueberry-100);
252
256
  }
253
257
 
254
- &:active {
258
+ &:active:not(div) {
255
259
  background-color: var(--color-action-background-ondark-hoverselected);
256
260
  }
257
261
  }
@@ -259,11 +263,11 @@
259
263
  &[aria-expanded='true'] {
260
264
  background-color: var(--core-color-blueberry-100);
261
265
 
262
- &:hover {
266
+ &:hover:not(div) {
263
267
  background-color: var(--core-color-blueberry-200);
264
268
  }
265
269
 
266
- &:active {
270
+ &:active:not(div) {
267
271
  background-color: var(--core-color-blueberry-300);
268
272
  }
269
273
  }
@@ -271,11 +275,11 @@
271
275
 
272
276
  &--cherry:not(.expander-list-link--outline, .expander-list-link--fill-negative) {
273
277
  &[aria-expanded='false'] {
274
- &:hover {
278
+ &:hover:not(div) {
275
279
  background-color: var(--core-color-cherry-100);
276
280
  }
277
281
 
278
- &:active {
282
+ &:active:not(div) {
279
283
  background-color: var(--core-color-cherry-200);
280
284
  }
281
285
  }
@@ -283,11 +287,11 @@
283
287
  &[aria-expanded='true'] {
284
288
  background-color: var(--core-color-cherry-100);
285
289
 
286
- &:hover {
290
+ &:hover:not(div) {
287
291
  background-color: var(--core-color-cherry-200);
288
292
  }
289
293
 
290
- &:active {
294
+ &:active:not(div) {
291
295
  background-color: var(--core-color-cherry-300);
292
296
  }
293
297
  }
@@ -295,11 +299,11 @@
295
299
 
296
300
  &--neutral:not(.expander-list-link--outline, .expander-list-link--fill-negative) {
297
301
  &[aria-expanded='false'] {
298
- &:hover {
302
+ &:hover:not(div) {
299
303
  background-color: var(--core-color-neutral-100);
300
304
  }
301
305
 
302
- &:active {
306
+ &:active:not(div) {
303
307
  background-color: var(--core-color-neutral-200);
304
308
  }
305
309
  }
@@ -307,11 +311,11 @@
307
311
  &[aria-expanded='true'] {
308
312
  background-color: var(--core-color-neutral-100);
309
313
 
310
- &:hover {
314
+ &:hover:not(div) {
311
315
  background-color: var(--core-color-neutral-200);
312
316
  }
313
317
 
314
- &:active {
318
+ &:active:not(div) {
315
319
  background-color: var(--core-color-neutral-300);
316
320
  }
317
321
  }
@@ -349,11 +353,11 @@
349
353
 
350
354
  &--blueberry {
351
355
  &[aria-expanded='false'] {
352
- &:hover {
356
+ &:hover:not(div) {
353
357
  background-color: var(--core-color-blueberry-50);
354
358
  }
355
359
 
356
- &:active {
360
+ &:active:not(div) {
357
361
  background-color: var(--core-color-blueberry-100);
358
362
  }
359
363
  }
@@ -361,11 +365,11 @@
361
365
  &[aria-expanded='true'] {
362
366
  background-color: var(--core-color-blueberry-50);
363
367
 
364
- &:hover {
368
+ &:hover:not(div) {
365
369
  background-color: var(--core-color-blueberry-100);
366
370
  }
367
371
 
368
- &:active {
372
+ &:active:not(div) {
369
373
  background-color: var(--core-color-blueberry-200);
370
374
  }
371
375
  }
@@ -373,11 +377,11 @@
373
377
 
374
378
  &--cherry {
375
379
  &[aria-expanded='false'] {
376
- &:hover {
380
+ &:hover:not(div) {
377
381
  background-color: var(--core-color-cherry-50);
378
382
  }
379
383
 
380
- &:active {
384
+ &:active:not(div) {
381
385
  background-color: var(--core-color-cherry-100);
382
386
  }
383
387
  }
@@ -385,11 +389,11 @@
385
389
  &[aria-expanded='true'] {
386
390
  background-color: var(--core-color-cherry-50);
387
391
 
388
- &:hover {
392
+ &:hover:not(div) {
389
393
  background-color: var(--core-color-cherry-100);
390
394
  }
391
395
 
392
- &:active {
396
+ &:active:not(div) {
393
397
  background-color: var(--core-color-cherry-200);
394
398
  }
395
399
  }
@@ -398,11 +402,11 @@
398
402
  &--neutral,
399
403
  &--white {
400
404
  &[aria-expanded='false'] {
401
- &:hover {
405
+ &:hover:not(div) {
402
406
  background-color: var(--core-color-neutral-50);
403
407
  }
404
408
 
405
- &:active {
409
+ &:active:not(div) {
406
410
  background-color: var(--core-color-neutral-100);
407
411
  }
408
412
  }
@@ -410,11 +414,11 @@
410
414
  &[aria-expanded='true'] {
411
415
  background-color: var(--core-color-neutral-50);
412
416
 
413
- &:hover {
417
+ &:hover:not(div) {
414
418
  background-color: var(--core-color-neutral-100);
415
419
  }
416
420
 
417
- &:active {
421
+ &:active:not(div) {
418
422
  background-color: var(--core-color-neutral-200);
419
423
  }
420
424
  }
@@ -429,22 +433,22 @@
429
433
  &--new {
430
434
  background-color: var(--core-color-blueberry-50) !important;
431
435
 
432
- &:hover {
436
+ &:hover:not(div) {
433
437
  background-color: var(--core-color-blueberry-100) !important;
434
438
  }
435
439
 
436
- &:active {
440
+ &:active:not(div) {
437
441
  background-color: var(--core-color-blueberry-200) !important;
438
442
  }
439
443
 
440
444
  &[aria-expanded='true'] {
441
445
  background-color: var(--core-color-blueberry-100) !important;
442
446
 
443
- &:hover {
447
+ &:hover:not(div) {
444
448
  background-color: var(--core-color-blueberry-200) !important;
445
449
  }
446
450
 
447
- &:active {
451
+ &:active:not(div) {
448
452
  background-color: var(--core-color-blueberry-300) !important;
449
453
  }
450
454
  }
@@ -0,0 +1,19 @@
1
+ import { default as React, AriaAttributes } from 'react';
2
+ import { HTMLButtonProps } from '../../constants';
3
+ import { HNDesignsystemFavoriteButton } from '../../resources/Resources';
4
+ export interface FavoriteButtonProps extends HTMLButtonProps, AriaAttributes {
5
+ /** Determines if the FavoriteButton is checked */
6
+ checked: boolean;
7
+ /** Gives a unique id to the button */
8
+ id?: string;
9
+ /** Function that is called when clicked */
10
+ onClick: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
11
+ /** Resources for component */
12
+ resources?: Partial<HNDesignsystemFavoriteButton>;
13
+ /** Specifies the focus order relative to the other buttons or controls on the page */
14
+ tabIndex?: number;
15
+ /** Sets the data-testid attribute. */
16
+ testId?: string;
17
+ }
18
+ export declare const FavoriteButton: React.ForwardRefExoticComponent<FavoriteButtonProps & React.RefAttributes<HTMLButtonElement>>;
19
+ export default FavoriteButton;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare const starIconNormalMobile: (isChecked: boolean, isActive: boolean) => React.JSX.Element;
2
+ export declare const starIconHoverMobile: (isChecked: boolean, isActive: boolean) => React.JSX.Element;
3
+ export declare const starIconNormalDesktop: (isChecked: boolean, isActive: boolean) => React.JSX.Element;
4
+ export declare const starIconHoverDesktop: (isChecked: boolean, isActive: boolean) => React.JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { FavoriteButton } from './FavoriteButton';
2
+ export * from './FavoriteButton';
3
+ export default FavoriteButton;
@@ -0,0 +1,209 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import React__default from "react";
3
+ import classNames from "classnames";
4
+ import { LanguageLocales, AnalyticsId } from "../../constants.js";
5
+ import styles from "./styles.module.scss";
6
+ import { useBreakpoint, Breakpoint } from "../../hooks/useBreakpoint.js";
7
+ import { usePseudoClasses } from "../../hooks/usePseudoClasses.js";
8
+ import { useLanguage } from "../../utils/language.js";
9
+ import { isMutableRefObject } from "../../utils/refs.js";
10
+ const ariaLabel = "Favorittmarkering";
11
+ const nbNO = {
12
+ ariaLabel
13
+ };
14
+ const getResources = (language) => {
15
+ switch (language) {
16
+ case LanguageLocales.NORWEGIAN:
17
+ default:
18
+ return nbNO;
19
+ }
20
+ };
21
+ const normalStroke = "var(--color-action-graphics-onlight)";
22
+ const normalFill = "transparent";
23
+ const hoverFill = "#126F8721";
24
+ const hoverStroke = "var(--color-action-graphics-onlight-hover)";
25
+ const activeStroke = "var(--core-color-blueberry-800)";
26
+ const fillColor = (isChecked, isActive, isHovered) => {
27
+ if (isChecked) {
28
+ if (isActive) {
29
+ return activeStroke;
30
+ } else {
31
+ if (isHovered) {
32
+ return hoverStroke;
33
+ } else {
34
+ return normalStroke;
35
+ }
36
+ }
37
+ } else {
38
+ if (isHovered) {
39
+ return hoverFill;
40
+ } else {
41
+ return normalFill;
42
+ }
43
+ }
44
+ };
45
+ const strokeColor = (isActive, isHovered) => {
46
+ if (isActive) {
47
+ return activeStroke;
48
+ } else {
49
+ if (isHovered) {
50
+ return hoverStroke;
51
+ } else {
52
+ return normalStroke;
53
+ }
54
+ }
55
+ };
56
+ const starIconNormalMobile = (isChecked, isActive) => {
57
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
58
+ /* @__PURE__ */ jsx(
59
+ "path",
60
+ {
61
+ d: "M20.1026 31.1787L13.4007 34.7023C10.833 36.0523 7.83185 33.8719 8.32233 31.0126L9.60261 23.5492L4.17653 18.2675C2.09656 16.2428 3.24317 12.712 6.11581 12.2956L13.5982 11.2112L16.9493 4.42107C18.2332 1.81969 21.9426 1.81969 23.2265 4.42107L26.5776 11.2112L34.06 12.2956C36.9326 12.712 38.0792 16.2428 35.9993 18.2675L30.5732 23.5492L31.852 31.0044C32.3428 33.8651 29.3386 36.0456 26.7708 34.6925L20.1026 31.1787Z",
62
+ stroke: "black",
63
+ fill: "transparent",
64
+ strokeWidth: "3",
65
+ strokeLinecap: "round",
66
+ className: styles["favoritebutton__star-icon--focus"],
67
+ display: "block"
68
+ }
69
+ ),
70
+ /* @__PURE__ */ jsx(
71
+ "path",
72
+ {
73
+ d: "M20.0961 26.5515L12.6372 30.4731L14.0621 22.1671L8.01953 16.2853L16.3582 15.0768L20.0877 7.52002L23.8171 15.0768L32.1558 16.2853L26.1133 22.1671L27.5381 30.4731L20.0961 26.5515Z",
74
+ stroke: strokeColor(isActive, false),
75
+ fill: fillColor(isChecked, isActive, false),
76
+ strokeWidth: "2.2",
77
+ strokeLinecap: "round",
78
+ strokeLinejoin: "round"
79
+ }
80
+ )
81
+ ] });
82
+ };
83
+ const starIconHoverMobile = (isChecked, isActive) => /* @__PURE__ */ jsxs(Fragment, { children: [
84
+ /* @__PURE__ */ jsx(
85
+ "path",
86
+ {
87
+ d: "M22.2128 31.4832L16.2246 36.117C13.9303 37.8924 10.5961 36.2662 10.5826 33.3653L10.5475 25.7929L4.28665 21.5336C1.88672 19.9009 2.40278 16.2246 5.15948 15.3158L12.3399 12.9486L14.461 5.67964C15.2736 2.89484 18.9267 2.2507 20.6428 4.58962L25.1221 10.6947L32.6791 10.4633C35.5804 10.3745 37.3227 13.6526 35.6259 16.0077L31.1994 22.1514L33.7534 29.2712C34.7335 32.0033 32.1536 34.6724 29.3898 33.7857L22.2128 31.4832Z",
88
+ stroke: "black",
89
+ fill: "transparent",
90
+ strokeWidth: "3",
91
+ strokeLinecap: "round",
92
+ className: styles["favoritebutton__star-icon--focus"]
93
+ }
94
+ ),
95
+ /* @__PURE__ */ jsx(
96
+ "path",
97
+ {
98
+ d: "M21.4079 26.8365L14.7433 31.9937L14.7041 23.5664L7.73204 18.8233L15.7342 16.1851L18.0947 8.09555L23.0798 14.8899L31.5016 14.6321L26.5722 21.4738L29.4178 29.4062L21.4079 26.8365Z",
99
+ stroke: strokeColor(isActive, true),
100
+ fill: fillColor(isChecked, isActive, true),
101
+ fillOpacity: isChecked ? "1" : "0.13",
102
+ strokeWidth: "2.2",
103
+ strokeLinecap: "round",
104
+ strokeLinejoin: "round"
105
+ }
106
+ )
107
+ ] });
108
+ const starIconNormalDesktop = (isChecked, isActive) => /* @__PURE__ */ jsxs(Fragment, { children: [
109
+ /* @__PURE__ */ jsx(
110
+ "path",
111
+ {
112
+ d: "M30.1061 44.1854L20.3139 49.3338C17.7461 50.6838 14.745 48.5034 15.2355 45.6441L17.1061 34.7394L9.17653 27.0207C7.09656 24.9961 8.24318 21.4653 11.1158 21.0489L22.053 19.4638L26.9493 9.54278C28.2331 6.9414 31.9426 6.94139 33.2265 9.54278L38.1227 19.4638L49.06 21.0489C51.9326 21.4653 53.0792 24.9961 50.9993 27.0207L43.0697 34.7394L44.9389 45.6359C45.4296 48.4966 42.4254 50.6772 39.8576 49.324L30.1061 44.1854Z",
113
+ stroke: "black",
114
+ fill: "transparent",
115
+ strokeWidth: "3",
116
+ strokeLinecap: "round",
117
+ className: styles["favoritebutton__star-icon--focus"]
118
+ }
119
+ ),
120
+ /* @__PURE__ */ jsx(
121
+ "path",
122
+ {
123
+ d: "M30.0998 39.4723L19.5927 44.9966L21.5998 33.2961L13.0879 25.0106L24.8343 23.3082L30.0879 12.6632L35.3414 23.3082L47.0879 25.0106L38.576 33.2961L40.5831 44.9966L30.0998 39.4723Z",
124
+ stroke: strokeColor(isActive, false),
125
+ fill: fillColor(isChecked, isActive, false),
126
+ strokeWidth: "2.5",
127
+ strokeLinecap: "round",
128
+ strokeLinejoin: "round"
129
+ }
130
+ )
131
+ ] });
132
+ const starIconHoverDesktop = (isChecked, isActive) => /* @__PURE__ */ jsxs(Fragment, { children: [
133
+ /* @__PURE__ */ jsx(
134
+ "path",
135
+ {
136
+ d: "M33.1609 44.7458L24.4114 51.5164C22.1171 53.2918 18.783 51.6656 18.7695 48.7646L18.7181 37.7007L9.56864 31.4763C7.1687 29.8436 7.68476 26.1672 10.4415 25.2584L20.9373 21.7982L24.0364 11.1776C24.849 8.39281 28.5021 7.74867 30.2182 10.0876L36.7629 19.0077L47.8092 18.6695C50.7105 18.5807 52.4528 21.8588 50.756 24.2138L44.2872 33.1922L48.0201 43.5985C49.0002 46.3306 46.4203 48.9997 43.6565 48.113L33.1609 44.7458Z",
137
+ stroke: "black",
138
+ fill: "transparent",
139
+ strokeWidth: "3",
140
+ strokeLinecap: "round",
141
+ className: styles["favoritebutton__star-icon--focus"]
142
+ }
143
+ ),
144
+ /* @__PURE__ */ jsx(
145
+ "path",
146
+ {
147
+ d: "M32.3991 40.1029L23.0108 47.3678L22.9557 35.4965L13.1343 28.815L24.4067 25.0987L27.732 13.7031L34.7542 23.2741L46.6178 22.9109L39.674 32.5486L43.6823 43.7228L32.3991 40.1029Z",
148
+ stroke: strokeColor(isActive, true),
149
+ fill: fillColor(isChecked, isActive, true),
150
+ fillOpacity: isChecked ? "1" : "0.13",
151
+ strokeWidth: "2.5",
152
+ strokeLinecap: "round",
153
+ strokeLinejoin: "round"
154
+ }
155
+ )
156
+ ] });
157
+ const FavoriteButton = React__default.forwardRef(function FavoriteButtonForwardedRef(props, ref) {
158
+ const { checked, id, onClick, resources, tabIndex, testId, ...other } = props;
159
+ const buttonWrapperClasses = classNames(styles.favoritebutton);
160
+ const { refObject, isHovered, isActive } = usePseudoClasses(isMutableRefObject(ref) ? ref : null);
161
+ const breakpoint = useBreakpoint();
162
+ const { language } = useLanguage(LanguageLocales.NORWEGIAN);
163
+ const defaultResources = getResources(language);
164
+ const mergedResources = {
165
+ ...defaultResources,
166
+ ...resources,
167
+ ariaLabel: other["aria-label"] || (resources == null ? void 0 : resources.ariaLabel) || defaultResources.ariaLabel
168
+ };
169
+ const isMobile = breakpoint <= Breakpoint.sm;
170
+ const starIcon = (() => {
171
+ if (isMobile) {
172
+ if (isHovered) {
173
+ return starIconHoverMobile(checked, isActive);
174
+ } else {
175
+ return starIconNormalMobile(checked, isActive);
176
+ }
177
+ } else {
178
+ if (isHovered) {
179
+ return starIconHoverDesktop(checked, isActive);
180
+ } else {
181
+ return starIconNormalDesktop(checked, isActive);
182
+ }
183
+ }
184
+ })();
185
+ return /* @__PURE__ */ jsx(
186
+ "button",
187
+ {
188
+ id,
189
+ onClick,
190
+ "data-testid": testId,
191
+ "data-analyticsid": AnalyticsId.FavoriteButton,
192
+ className: buttonWrapperClasses,
193
+ ref: refObject,
194
+ tabIndex,
195
+ role: "switch",
196
+ "aria-checked": checked,
197
+ type: "button",
198
+ "aria-label": mergedResources.ariaLabel,
199
+ ...other,
200
+ children: /* @__PURE__ */ jsx("svg", { focusable: false, overflow: "visible", role: "presentation", viewBox: isMobile ? "0 0 41 41" : "0 0 61 61", ...other, children: starIcon })
201
+ }
202
+ );
203
+ });
204
+ FavoriteButton.displayName = "FavoriteButton";
205
+ export {
206
+ FavoriteButton,
207
+ FavoriteButton as default
208
+ };
209
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/FavoriteButton/resourceHelper.ts","../../../src/components/FavoriteButton/StarIcon.tsx","../../../src/components/FavoriteButton/FavoriteButton.tsx"],"sourcesContent":["import { LanguageLocales } from '../../constants';\nimport nbNO from '../../resources/HN.Designsystem.FavoriteButton.nb-NO.json';\nimport { HNDesignsystemFavoriteButton } from '../../resources/Resources';\n\nexport const getResources = (language: LanguageLocales): HNDesignsystemFavoriteButton => {\n switch (language) {\n case LanguageLocales.NORWEGIAN:\n default:\n return nbNO;\n }\n};\n","import styles from './styles.module.scss';\n\nconst normalStroke = 'var(--color-action-graphics-onlight)';\nconst normalFill = 'transparent';\nconst hoverFill = '#126F8721'; // kan ikke bruke transparent token på svg\nconst hoverStroke = 'var(--color-action-graphics-onlight-hover)';\nconst activeStroke = 'var(--core-color-blueberry-800)';\n\nconst fillColor = (isChecked: boolean, isActive: boolean, isHovered: boolean): string => {\n if (isChecked) {\n if (isActive) {\n return activeStroke;\n } else {\n if (isHovered) {\n return hoverStroke;\n } else {\n return normalStroke;\n }\n }\n } else {\n if (isHovered) {\n return hoverFill;\n } else {\n return normalFill;\n }\n }\n};\n\nconst strokeColor = (isActive: boolean, isHovered: boolean): string => {\n if (isActive) {\n return activeStroke;\n } else {\n if (isHovered) {\n return hoverStroke;\n } else {\n return normalStroke;\n }\n }\n};\n\nexport const starIconNormalMobile = (isChecked: boolean, isActive: boolean): React.JSX.Element => {\n return (\n <>\n <path\n d=\"M20.1026 31.1787L13.4007 34.7023C10.833 36.0523 7.83185 33.8719 8.32233 31.0126L9.60261 23.5492L4.17653 18.2675C2.09656 16.2428 3.24317 12.712 6.11581 12.2956L13.5982 11.2112L16.9493 4.42107C18.2332 1.81969 21.9426 1.81969 23.2265 4.42107L26.5776 11.2112L34.06 12.2956C36.9326 12.712 38.0792 16.2428 35.9993 18.2675L30.5732 23.5492L31.852 31.0044C32.3428 33.8651 29.3386 36.0456 26.7708 34.6925L20.1026 31.1787Z\"\n stroke=\"black\"\n fill=\"transparent\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n className={styles['favoritebutton__star-icon--focus']}\n display=\"block\"\n />\n <path\n d=\"M20.0961 26.5515L12.6372 30.4731L14.0621 22.1671L8.01953 16.2853L16.3582 15.0768L20.0877 7.52002L23.8171 15.0768L32.1558 16.2853L26.1133 22.1671L27.5381 30.4731L20.0961 26.5515Z\"\n stroke={strokeColor(isActive, false)}\n fill={fillColor(isChecked, isActive, false)}\n strokeWidth=\"2.2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </>\n );\n};\n\nexport const starIconHoverMobile = (isChecked: boolean, isActive: boolean): React.JSX.Element => (\n <>\n <path\n d=\"M22.2128 31.4832L16.2246 36.117C13.9303 37.8924 10.5961 36.2662 10.5826 33.3653L10.5475 25.7929L4.28665 21.5336C1.88672 19.9009 2.40278 16.2246 5.15948 15.3158L12.3399 12.9486L14.461 5.67964C15.2736 2.89484 18.9267 2.2507 20.6428 4.58962L25.1221 10.6947L32.6791 10.4633C35.5804 10.3745 37.3227 13.6526 35.6259 16.0077L31.1994 22.1514L33.7534 29.2712C34.7335 32.0033 32.1536 34.6724 29.3898 33.7857L22.2128 31.4832Z\"\n stroke=\"black\"\n fill=\"transparent\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n className={styles['favoritebutton__star-icon--focus']}\n />\n <path\n d=\"M21.4079 26.8365L14.7433 31.9937L14.7041 23.5664L7.73204 18.8233L15.7342 16.1851L18.0947 8.09555L23.0798 14.8899L31.5016 14.6321L26.5722 21.4738L29.4178 29.4062L21.4079 26.8365Z\"\n stroke={strokeColor(isActive, true)}\n fill={fillColor(isChecked, isActive, true)}\n fillOpacity={isChecked ? '1' : '0.13'}\n strokeWidth=\"2.2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </>\n);\nexport const starIconNormalDesktop = (isChecked: boolean, isActive: boolean): React.JSX.Element => (\n <>\n <path\n d=\"M30.1061 44.1854L20.3139 49.3338C17.7461 50.6838 14.745 48.5034 15.2355 45.6441L17.1061 34.7394L9.17653 27.0207C7.09656 24.9961 8.24318 21.4653 11.1158 21.0489L22.053 19.4638L26.9493 9.54278C28.2331 6.9414 31.9426 6.94139 33.2265 9.54278L38.1227 19.4638L49.06 21.0489C51.9326 21.4653 53.0792 24.9961 50.9993 27.0207L43.0697 34.7394L44.9389 45.6359C45.4296 48.4966 42.4254 50.6772 39.8576 49.324L30.1061 44.1854Z\"\n stroke=\"black\"\n fill=\"transparent\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n className={styles['favoritebutton__star-icon--focus']}\n />\n <path\n d=\"M30.0998 39.4723L19.5927 44.9966L21.5998 33.2961L13.0879 25.0106L24.8343 23.3082L30.0879 12.6632L35.3414 23.3082L47.0879 25.0106L38.576 33.2961L40.5831 44.9966L30.0998 39.4723Z\"\n stroke={strokeColor(isActive, false)}\n fill={fillColor(isChecked, isActive, false)}\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </>\n);\n\nexport const starIconHoverDesktop = (isChecked: boolean, isActive: boolean): React.JSX.Element => (\n <>\n <path\n d=\"M33.1609 44.7458L24.4114 51.5164C22.1171 53.2918 18.783 51.6656 18.7695 48.7646L18.7181 37.7007L9.56864 31.4763C7.1687 29.8436 7.68476 26.1672 10.4415 25.2584L20.9373 21.7982L24.0364 11.1776C24.849 8.39281 28.5021 7.74867 30.2182 10.0876L36.7629 19.0077L47.8092 18.6695C50.7105 18.5807 52.4528 21.8588 50.756 24.2138L44.2872 33.1922L48.0201 43.5985C49.0002 46.3306 46.4203 48.9997 43.6565 48.113L33.1609 44.7458Z\"\n stroke=\"black\"\n fill=\"transparent\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n className={styles['favoritebutton__star-icon--focus']}\n />\n <path\n d=\"M32.3991 40.1029L23.0108 47.3678L22.9557 35.4965L13.1343 28.815L24.4067 25.0987L27.732 13.7031L34.7542 23.2741L46.6178 22.9109L39.674 32.5486L43.6823 43.7228L32.3991 40.1029Z\"\n stroke={strokeColor(isActive, true)}\n fill={fillColor(isChecked, isActive, true)}\n fillOpacity={isChecked ? '1' : '0.13'}\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </>\n);\n","import React, { AriaAttributes } from 'react';\n\nimport classNames from 'classnames';\n\nimport { getResources } from './resourceHelper';\nimport { starIconHoverDesktop, starIconHoverMobile, starIconNormalDesktop, starIconNormalMobile } from './StarIcon';\nimport { AnalyticsId, HTMLButtonProps, LanguageLocales } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { HNDesignsystemFavoriteButton } from '../../resources/Resources';\nimport { useLanguage } from '../../utils/language';\nimport { isMutableRefObject } from '../../utils/refs';\n\nimport styles from './styles.module.scss';\n\nexport interface FavoriteButtonProps extends HTMLButtonProps, AriaAttributes {\n /** Determines if the FavoriteButton is checked */\n checked: boolean;\n /** Gives a unique id to the button */\n id?: string;\n /** Function that is called when clicked */\n onClick: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n /** Resources for component */\n resources?: Partial<HNDesignsystemFavoriteButton>;\n /** Specifies the focus order relative to the other buttons or controls on the page */\n tabIndex?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const FavoriteButton = React.forwardRef(function FavoriteButtonForwardedRef(\n props: FavoriteButtonProps,\n ref: React.ForwardedRef<HTMLButtonElement>\n) {\n const { checked, id, onClick, resources, tabIndex, testId, ...other } = props;\n\n const buttonWrapperClasses = classNames(styles.favoritebutton);\n const { refObject, isHovered, isActive } = usePseudoClasses<HTMLButtonElement>(isMutableRefObject(ref) ? ref : null);\n const breakpoint = useBreakpoint();\n const { language } = useLanguage<LanguageLocales>(LanguageLocales.NORWEGIAN);\n const defaultResources = getResources(language);\n\n const mergedResources: HNDesignsystemFavoriteButton = {\n ...defaultResources,\n ...resources,\n ariaLabel: other['aria-label'] || resources?.ariaLabel || defaultResources.ariaLabel,\n };\n\n const isMobile = breakpoint <= Breakpoint.sm;\n\n const starIcon = ((): React.JSX.Element => {\n if (isMobile) {\n if (isHovered) {\n return starIconHoverMobile(checked, isActive);\n } else {\n return starIconNormalMobile(checked, isActive);\n }\n } else {\n if (isHovered) {\n return starIconHoverDesktop(checked, isActive);\n } else {\n return starIconNormalDesktop(checked, isActive);\n }\n }\n })();\n\n return (\n <button\n id={id}\n onClick={onClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.FavoriteButton}\n className={buttonWrapperClasses}\n ref={refObject}\n tabIndex={tabIndex}\n role=\"switch\"\n aria-checked={checked}\n type=\"button\"\n aria-label={mergedResources.ariaLabel}\n {...other}\n >\n <svg focusable={false} overflow=\"visible\" role=\"presentation\" viewBox={isMobile ? '0 0 41 41' : '0 0 61 61'} {...other}>\n {starIcon}\n </svg>\n </button>\n );\n});\n\nFavoriteButton.displayName = 'FavoriteButton';\n\nexport default FavoriteButton;\n"],"names":["React"],"mappings":";;;;;;;;;;;;;AAIO,MAAM,eAAe,CAAC,aAA4D;AACvF,UAAQ,UAAA;AAAA,IACN,KAAK,gBAAgB;AAAA,IACrB;AACE,aAAO;AAAA,EAAA;AAEb;ACRA,MAAM,eAAe;AACrB,MAAM,aAAa;AACnB,MAAM,YAAY;AAClB,MAAM,cAAc;AACpB,MAAM,eAAe;AAErB,MAAM,YAAY,CAAC,WAAoB,UAAmB,cAA+B;AACvF,MAAI,WAAW;AACb,QAAI,UAAU;AACZ,aAAO;AAAA,IACT,OAAO;AACL,UAAI,WAAW;AACb,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,OAAO;AACL,QAAI,WAAW;AACb,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,MAAM,cAAc,CAAC,UAAmB,cAA+B;AACrE,MAAI,UAAU;AACZ,WAAO;AAAA,EACT,OAAO;AACL,QAAI,WAAW;AACb,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,uBAAuB,CAAC,WAAoB,aAAyC;AAChG,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,GAAE;AAAA,QACF,QAAO;AAAA,QACP,MAAK;AAAA,QACL,aAAY;AAAA,QACZ,eAAc;AAAA,QACd,WAAW,OAAO,kCAAkC;AAAA,QACpD,SAAQ;AAAA,MAAA;AAAA,IAAA;AAAA,IAEV;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,GAAE;AAAA,QACF,QAAQ,YAAY,UAAU,KAAK;AAAA,QACnC,MAAM,UAAU,WAAW,UAAU,KAAK;AAAA,QAC1C,aAAY;AAAA,QACZ,eAAc;AAAA,QACd,gBAAe;AAAA,MAAA;AAAA,I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AA,MACA,MAAK;AAAA,MACL,gBAAc;AAAA,MACd,MAAK;AAAA,MACL,cAAY,gBAAgB;AAAA,MAC3B,GAAG;AAAA,MAEJ,UAAA,oBAAC,OAAA,EAAI,WAAW,OAAO,UAAS,WAAU,MAAK,gBAAe,SAAS,WAAW,cAAc,aAAc,GAAG,OAC9G,UAAA,SAAA,CACH;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;AAED,eAAe,cAAc;"}
@@ -0,0 +1,3 @@
1
+ import { LanguageLocales } from '../../constants';
2
+ import { HNDesignsystemFavoriteButton } from '../../resources/Resources';
3
+ export declare const getResources: (language: LanguageLocales) => HNDesignsystemFavoriteButton;
@@ -0,0 +1,22 @@
1
+ @use 'sass:map';
2
+ @use '../../scss/breakpoints' as breakpoints;
3
+ @use '../../scss/spacers' as spacers;
4
+
5
+ .story {
6
+ &__title {
7
+ display: inline;
8
+ padding-right: spacers.getSpacer(2xl);
9
+ }
10
+
11
+ &__hjelpetrigger {
12
+ display: inline-flex;
13
+ position: relative;
14
+ margin-left: spacers.getSpacer(xl) * -1;
15
+
16
+ span {
17
+ display: inline-flex;
18
+ align-items: center;
19
+ justify-content: center;
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,10 @@
1
+ export type Styles = {
2
+ story__hjelpetrigger: string;
3
+ story__title: string;
4
+ };
5
+
6
+ export type ClassNames = keyof Styles;
7
+
8
+ declare const styles: Styles;
9
+
10
+ export default styles;