diff --git a/apps/store/src/components/ProductCard/DetailsList/DetailsList.stories.tsx b/apps/store/src/components/ProductCard/DetailsList/DetailsList.stories.tsx index c48593258d..4de84e6330 100644 --- a/apps/store/src/components/ProductCard/DetailsList/DetailsList.stories.tsx +++ b/apps/store/src/components/ProductCard/DetailsList/DetailsList.stories.tsx @@ -8,7 +8,7 @@ import { DetailsList } from './DetailsList' type Controls = ComponentProps const meta: Meta = { - title: 'Components / Product Card / DetailsList', + title: 'Components / ProductCard / DetailsList', component: DetailsList.Root, parameters: { design: { diff --git a/apps/store/src/components/ProductCard/Divider.tsx b/apps/store/src/components/ProductCard/Divider.tsx new file mode 100644 index 0000000000..5ea69f7afe --- /dev/null +++ b/apps/store/src/components/ProductCard/Divider.tsx @@ -0,0 +1,14 @@ +import { tokens } from 'ui' + +export const Divider = () => { + return ( +
+ ) +} diff --git a/apps/store/src/components/ProductCard/ProductCard.stories.tsx b/apps/store/src/components/ProductCard/ProductCard.stories.tsx new file mode 100644 index 0000000000..04ca14f56b --- /dev/null +++ b/apps/store/src/components/ProductCard/ProductCard.stories.tsx @@ -0,0 +1,121 @@ +import type { Meta, StoryObj } from '@storybook/react' +import { type ComponentProps } from 'react' +import { Badge, BasePillow, Button, Card, CrossIcon, IconButton, sprinkles, Text, tokens } from 'ui' +import { CurrencyCode } from '@/services/graphql/graphql' +import { InputStartDay } from '../InputDay/InputStartDay' +import { Price } from '../Price' +import { DetailsList } from './DetailsList/DetailsList' +import { Divider } from './Divider' +import { ProductCardDetails } from './ProductCardDetails' + +type Controls = ComponentProps + +const meta: Meta = { + title: 'Components / ProductCard', + component: Card.Root, + argTypes: { + variant: { + options: ['primary', 'secondary'], + control: { type: 'select' }, + }, + }, + parameters: { + design: { + allowFullscreen: true, + type: 'figma', + url: 'https://www.figma.com/file/5kmmDdh6StpXzbEfr7WevV/Hedvig-UI-Kit?type=design&node-id=18673-5100', + }, + }, +} +export default meta + +type Story = StoryObj + +export const Default: Story = { + render: (args: Controls) => ( +
+ + + + + + + + + + + + Homeowner Insurance + Bellmansgatan 19A + + + + + + {(isOpen) => (isOpen ? 'Hide details' : 'Show details')} + + + + Details + + + Home type + Homeowner + + + + Address + Bellmansgatan 19A + + + + Zip code + 118 47 + + + + + + + + + + + + Homeowner Insurance{' '} + + Max + + + 379 kr/mo + + + + Extended travel 60 days + 79 kr/mo + + + + + + + + Total + + + + + + +
+ ), + args: { + variant: 'primary', + }, +} diff --git a/apps/store/src/components/ProductCard/ProductCardDetails.tsx b/apps/store/src/components/ProductCard/ProductCardDetails.tsx new file mode 100644 index 0000000000..7da6c5e212 --- /dev/null +++ b/apps/store/src/components/ProductCard/ProductCardDetails.tsx @@ -0,0 +1,66 @@ +import { type ComponentProps, createContext, type ReactNode, useContext, useState } from 'react' +import { Button } from 'ui' +import Collapsible from '@/components/Collapsible/Collapsible' + +type ContextValue = { + isOpen: boolean + toggle: () => void +} + +const Context = createContext(null) + +const useProductDetails = () => { + const context = useContext(Context) + + if (!context) { + throw new Error('useProductDetails must be used inside ProductCardDetails') + } + + return context +} + +type RootProps = ComponentProps +const Root = ({ children, ...props }: RootProps) => { + const [isOpen, setIsOpen] = useState(false) + + const toggle = () => { + setIsOpen((isOpen) => !isOpen) + } + + return ( + + {children} + + ) +} + +type TriggerProps = Omit, 'children'> & { + children?: ((isOpen: boolean) => ReactNode) | ReactNode +} +const Trigger = ({ children, ...props }: TriggerProps) => { + const { isOpen, toggle } = useProductDetails() + + return ( + + + + ) +} + +type ContentProps = ComponentProps<'div'> +const Content = ({ children, ...props }: ContentProps) => { + return ( + + {/* This `div` wraps all content not to conflict with `Collapsible.Content` animation */} +
{children}
+
+ ) +} + +export const ProductCardDetails = { + Root, + Trigger, + Content, +}