diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-24 19:35:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-24 19:35:12 +0200 |
| commit | c85ab5ad43ccf52881ee224672c41ec30021cf48 (patch) | |
| tree | 8058808d9bfca19383f120c46b34d99ff2f89f63 /src/components/WidgetParts/ExpandableWidget | |
| parent | 52404177c07a2aab7fc894362fb3060dff2431a0 (diff) | |
| parent | 11b9de44a4b2f305a6a484187805e429b2767118 (diff) | |
refactor: use storybook and atomic design (#16)
BREAKING CHANGE: rewrite most of the Typescript types, so the content format (the meta in particular) needs to be updated.
Diffstat (limited to 'src/components/WidgetParts/ExpandableWidget')
| -rw-r--r-- | src/components/WidgetParts/ExpandableWidget/ExpandableWidget.module.scss | 146 | ||||
| -rw-r--r-- | src/components/WidgetParts/ExpandableWidget/ExpandableWidget.tsx | 61 |
2 files changed, 0 insertions, 207 deletions
diff --git a/src/components/WidgetParts/ExpandableWidget/ExpandableWidget.module.scss b/src/components/WidgetParts/ExpandableWidget/ExpandableWidget.module.scss deleted file mode 100644 index 6a7757d..0000000 --- a/src/components/WidgetParts/ExpandableWidget/ExpandableWidget.module.scss +++ /dev/null @@ -1,146 +0,0 @@ -@use "@styles/abstracts/functions" as fun; -@use "@styles/abstracts/mixins" as mix; - -.title { - margin: 0; - padding: 0; - background: none; - font-size: var(--font-size-xl); - text-align: left; -} - -.icon { - display: flex; - flex-flow: row nowrap; - align-items: center; - justify-content: center; - width: fun.convert-px(30); - height: fun.convert-px(30); - background: var(--color-bg); - border: fun.convert-px(1) solid var(--color-primary); - border-radius: fun.convert-px(3); - color: var(--color-primary); - font-weight: 800; - transition: all 0.25s ease-in-out 0s; - - &::before, - &::after { - content: ""; - background: var(--color-primary); - transition: all 0.4s ease-out 0s; - } - - &::before { - width: 10%; - height: 60%; - position: relative; - left: 30%; - } - - &::after { - width: 60%; - height: 10%; - position: relative; - left: -5%; - } -} - -.body { - width: 100%; - max-height: 0; - margin: 0 0 fun.convert-px(-6); // collapse borders - overflow: hidden; - visibility: hidden; - transition: all 0.6s cubic-bezier(0, 1, 0, 1) 0s, margin 0.2s ease-in-out 0s, - border 0.1s ease-in-out 0.3s, visibility 0.1s linear 0.6s; - - &--borders { - border: 0 solid transparent; - } - - > *:last-child { - margin-bottom: 0; - } - - @include mix.media("screen") { - @include mix.dimensions("md") { - font-size: var(--font-size-sm); - font-weight: 500; - } - } -} - -.wrapper { - --header-height: #{fun.convert-px(65)}; - - display: flex; - flex-flow: column; - - &--expanded { - .icon::before { - height: 0; - } - - .body { - max-height: 10000px; // needs a fixed value for transition. - margin: var(--spacing-sm) 0; - overflow: visible; - visibility: visible; - transition: visibility 0.1s linear 0s, max-height 0.6s linear 0s, - margin 0.2s ease-in-out 0s; - - &--borders { - border: fun.convert-px(2) solid var(--color-primary-dark); - } - } - } -} - -.wrapper--expanded.wrapper--toc { - @include mix.media("screen") { - @include mix.dimensions("lg") { - max-height: 100vh; - - .body { - overflow-y: auto; - } - } - } -} - -.header { - display: flex; - flex-flow: row nowrap; - align-items: center; - justify-content: space-between; - gap: var(--spacing-md); - width: 100%; - min-height: var(--header-height); - padding: 0; - position: sticky; - top: 0; - z-index: 3; - background: var(--color-bg); - border: none; - border-top: fun.convert-px(2) solid var(--color-primary-dark); - border-bottom: fun.convert-px(2) solid var(--color-primary-dark); - cursor: pointer; - - &:hover, - &:focus { - .icon { - background: var(--color-primary-light); - color: var(--color-fg-inverted); - transform: scale(1.2); - - &::before, - &::after { - background: var(--color-bg); - } - } - } - - > button { - padding: 0 var(--spacing-xs); - } -} diff --git a/src/components/WidgetParts/ExpandableWidget/ExpandableWidget.tsx b/src/components/WidgetParts/ExpandableWidget/ExpandableWidget.tsx deleted file mode 100644 index 38e57ad..0000000 --- a/src/components/WidgetParts/ExpandableWidget/ExpandableWidget.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { TitleLevel } from '@ts/types/app'; -import { ReactNode, useState } from 'react'; -import { useIntl } from 'react-intl'; -import styles from './ExpandableWidget.module.scss'; - -const ExpandableWidget = ({ - children, - title, - titleLevel = 2, - expand = false, - withBorders = false, - kind = 'regular', -}: { - children: ReactNode; - title: string; - titleLevel?: TitleLevel; - expand?: boolean; - withBorders?: boolean; - kind?: 'regular' | 'toc'; -}) => { - const intl = useIntl(); - const [isExpanded, setIsExpanded] = useState<boolean>(expand); - - const handleExpanse = () => setIsExpanded((prev) => !prev); - - const TitleTag = `h${titleLevel}` as keyof JSX.IntrinsicElements; - - const wrapperKindClass = styles[`wrapper--${kind}`]; - const wrapperClasses = `${styles.wrapper} ${ - isExpanded ? styles['wrapper--expanded'] : '' - } ${wrapperKindClass}`; - - const bodyClasses = `${styles.body} ${ - withBorders ? styles['body--borders'] : '' - }`; - - return ( - <div className={wrapperClasses}> - <button type="button" className={styles.header} onClick={handleExpanse}> - <span className="screen-reader-text"> - {isExpanded - ? intl.formatMessage({ - defaultMessage: 'Collapse', - description: 'ExpandableWidget: collapse text', - id: 'WRkY1/', - }) - : intl.formatMessage({ - defaultMessage: 'Expand', - description: 'ExpandableWidget: expand text', - id: 'hV0qHp', - })} - </span> - <TitleTag className={styles.title}>{title}</TitleTag> - <span className={styles.icon} aria-hidden={true}></span> - </button> - <div className={bodyClasses}>{children}</div> - </div> - ); -}; - -export default ExpandableWidget; |
