refactor: création d'un élément réutilisable RotatingChevronIcon
parent
9e307ebd36
commit
c1b272e1ca
|
@ -1,6 +1,7 @@
|
|||
import { Meta } from '@storybook/react'
|
||||
import { Meta, StoryObj } from '@storybook/react'
|
||||
import { ComponentProps, useState } from 'react'
|
||||
|
||||
import { SvgIcon } from '.'
|
||||
import { RotatingChevronIcon, SvgIcon } from '.'
|
||||
|
||||
const meta: Meta<typeof SvgIcon> = {
|
||||
component: SvgIcon,
|
||||
|
@ -32,3 +33,25 @@ export {
|
|||
TriangleIcon,
|
||||
WarningIcon,
|
||||
} from '@/design-system/icons'
|
||||
|
||||
const RotatingChevronExample = (
|
||||
args: ComponentProps<typeof RotatingChevronIcon>
|
||||
) => {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<>
|
||||
<button onClick={() => setIsOpen(!isOpen)}>
|
||||
{isOpen ? 'Ouvert' : 'Fermé'}
|
||||
<RotatingChevronIcon {...args} $isOpen={isOpen} />
|
||||
</button>
|
||||
{isOpen && <div>Visible si ouvert</div>}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
type Story = StoryObj<typeof RotatingChevronExample>
|
||||
|
||||
export const Chevron: Story = {
|
||||
render: (args) => <RotatingChevronExample {...args} />,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { HTMLAttributes } from 'react'
|
||||
import { styled } from 'styled-components'
|
||||
import { css, styled } from 'styled-components'
|
||||
|
||||
export const SvgIcon = styled.svg`
|
||||
/* width: ${({ theme }) => theme.spacings.lg};
|
||||
|
@ -27,6 +27,17 @@ export const ChevronIcon = (props: HTMLAttributes<SVGElement>) => (
|
|||
</SvgIcon>
|
||||
)
|
||||
|
||||
export const RotatingChevronIcon = styled(ChevronIcon)<{ $isOpen: boolean }>`
|
||||
vertical-align: middle;
|
||||
transform: rotate(-90deg);
|
||||
transition: transform 0.3s;
|
||||
${({ $isOpen }) =>
|
||||
!$isOpen &&
|
||||
css`
|
||||
transform: rotate(90deg);
|
||||
`}
|
||||
`
|
||||
|
||||
export const InfoIcon = (props: HTMLAttributes<SVGElement>) => (
|
||||
<SvgIcon
|
||||
{...props}
|
||||
|
|
|
@ -7,7 +7,7 @@ import { Appear } from '@/components/ui/animate'
|
|||
import { Chip } from '@/design-system'
|
||||
import { Button } from '@/design-system/buttons'
|
||||
import { RadioCardSkeleton } from '@/design-system/field/Radio/RadioCard'
|
||||
import { ChevronIcon } from '@/design-system/icons'
|
||||
import { RotatingChevronIcon } from '@/design-system/icons'
|
||||
import { Grid } from '@/design-system/layout'
|
||||
import { H4, H5, H6 } from '@/design-system/typography/heading'
|
||||
import { Li, Ul } from '@/design-system/typography/list'
|
||||
|
@ -141,15 +141,7 @@ const StyledButton = styled(Button)`
|
|||
}
|
||||
`}
|
||||
`
|
||||
const StyledChevron = styled(ChevronIcon)<{ $isOpen: boolean }>`
|
||||
vertical-align: middle;
|
||||
transform: rotate(-90deg);
|
||||
transition: transform 0.3s;
|
||||
${({ $isOpen }) =>
|
||||
!$isOpen &&
|
||||
css`
|
||||
transform: rotate(90deg);
|
||||
`}
|
||||
const StyledChevron = styled(RotatingChevronIcon)`
|
||||
${({ theme }) =>
|
||||
theme.darkMode &&
|
||||
css`
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { formatValue, PublicodesExpression } from 'publicodes'
|
||||
import { useState } from 'react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { css, styled } from 'styled-components'
|
||||
import { styled } from 'styled-components'
|
||||
|
||||
import NumberInput from '@/components/conversation/NumberInput'
|
||||
import { Condition } from '@/components/EngineValue/Condition'
|
||||
|
@ -10,7 +10,11 @@ import { useEngine } from '@/components/utils/EngineContext'
|
|||
import { Message, NumberField } from '@/design-system'
|
||||
import { Button, HelpButtonWithPopover } from '@/design-system/buttons'
|
||||
import { FlexCenter } from '@/design-system/global-style'
|
||||
import { ChevronIcon, SearchIcon, WarningIcon } from '@/design-system/icons'
|
||||
import {
|
||||
RotatingChevronIcon,
|
||||
SearchIcon,
|
||||
WarningIcon,
|
||||
} from '@/design-system/icons'
|
||||
import { Tooltip } from '@/design-system/tooltip'
|
||||
import { Body, SmallBody } from '@/design-system/typography/paragraphs'
|
||||
|
||||
|
@ -128,7 +132,7 @@ export default function RéductionGénéraleMoisParMoisRow({
|
|||
aria-label={!isOptionVisible ? t('Déplier') : t('Replier')}
|
||||
>
|
||||
{t('Options')}
|
||||
<StyledChevron aria-hidden $isOpen={isOptionVisible} />
|
||||
<RotatingChevronIcon aria-hidden $isOpen={isOptionVisible} />
|
||||
</Button>
|
||||
</td>
|
||||
<td
|
||||
|
@ -264,14 +268,3 @@ const OptionContainer = styled.div`
|
|||
const StyledSmallBody = styled(SmallBody)`
|
||||
margin: 0;
|
||||
`
|
||||
|
||||
const StyledChevron = styled(ChevronIcon)<{ $isOpen: boolean }>`
|
||||
vertical-align: middle;
|
||||
transform: rotate(-90deg);
|
||||
transition: transform 0.3s;
|
||||
${({ $isOpen }) =>
|
||||
!$isOpen &&
|
||||
css`
|
||||
transform: rotate(90deg);
|
||||
`}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue