import { ReactNode } from 'react'; import { Meta } from '@storybook/react-webpack5'; import { useRtlDiffI18n, withRTLDiff } from '../../../.storybook/decorators/RtlDiffDecorator'; import Link from '../../Link'; import { lorem20 } from '../../test-utils'; import { ListItem, type ListItemProps } from '../ListItem'; import { SB_LIST_ITEM_CONTROLS as CONTROLS, SB_LIST_ITEM_MEDIA as MEDIA, SB_ListItem_ControlType as ControlType, } from './subcomponents'; import { VariantList, type VariantContent, type VariantStoryProps } from './variants/helpers'; /** Arabic stand-in for `lorem20`, of comparable word count so wrapping behaviour stays comparable. */ const arabicFiller = 'نص تجريبي يُستخدم لعرض شكل التصميم النهائي قبل إضافة المحتوى الفعلي، ويساعد في التحقق من سلوك التغليف والمحاذاة عند تجاوز السطر الواحد.'; const i18nMap = { title: { en: 'This is a title', ar: 'هذا عنوان' }, subtitle: { en: 'And it also has a subtitle', ar: 'وله أيضًا عنوان فرعي' }, longTitle: { en: `This is a long title. ${lorem20}`, ar: `هذا عنوان طويل. ${arabicFiller}` }, longSubtitle: { en: `And it also has a long subtitle. ${lorem20}`, ar: `وله أيضًا عنوان فرعي طويل. ${arabicFiller}`, }, valueTitleLine1: { en: 'This value title', ar: 'عنوان القيمة هذا' }, valueTitleLine2: { en: 'is made to span', ar: 'مُصمم ليمتد' }, valueTitleLine3: { en: 'across few lines', ar: 'على عدة أسطر' }, additionalInfo: { en: 'Which is augmented with additional info.', ar: 'والذي تمت إضافة معلومات إضافية إليه.', }, additionalInfoAction: { en: 'Details about the subject.', ar: 'تفاصيل حول الموضوع.' }, prompt: { en: 'Finally, there is a prompt.', ar: 'وأخيرًا، هناك تنبيه.' }, promptStart: { en: 'Finally, there is a prompt', ar: 'وأخيرًا، هناك تنبيه' }, promptLink: { en: 'referencing some details', ar: 'يشير إلى بعض التفاصيل' }, promptEnd: { en: 'for your convenience.', ar: 'لتسهيل الأمر عليك.' }, controlLabel: { en: 'Click me', ar: 'انقر هنا' }, }; type ListItemI18n = Record; /** * Amounts keep Latin digits and ISO currency codes in both columns — a bidi run inside RTL copy is * exactly what these stories need to exercise. */ const getContent = (i18n: ListItemI18n): VariantContent => ({ text: { title: i18n.title, subtitle: i18n.subtitle, valueTitle: '100 GBP', valueSubtitle: '200 USD', longTitle: i18n.longTitle, longSubtitle: i18n.longSubtitle, longValueTitle: ( <> {i18n.valueTitleLine1}
{i18n.valueTitleLine2}
{i18n.valueTitleLine3} ), }, media: MEDIA.avatarSingle, additionalInfo: { interactive: ( {i18n.additionalInfo} ), nonInteractive: {i18n.additionalInfo}, }, prompt: { interactive: ( {i18n.promptStart}{' '} {i18n.promptLink} {' '} {i18n.promptEnd} ), nonInteractive: {i18n.prompt}, }, }); /** Only the four controls with visible copy need overriding; the rest are icon- or input-only. */ const getControls = (i18n: ListItemI18n): Record => ({ ...CONTROLS, button: {}}>{i18n.controlLabel}, buttonAsLink: {i18n.controlLabel}, partialButton: ( {}}> {i18n.controlLabel} ), partialButtonAsLink: ( {i18n.controlLabel} ), }); const LocalisedVariantList = ({ controlType, variant }: VariantStoryProps) => { const i18n = useRtlDiffI18n(); return ( ); }; export default { component: ListItem, title: 'Content/ListItem/Tests/RTL Diff', tags: ['!autodocs', '!manifest'], ...withRTLDiff({ width: 'stretch', i18n: i18nMap, fixedRows: { heights: 'auto' }, }), } satisfies Meta; const Default = { render: ({ controlType, variant }: VariantStoryProps) => ( ), parameters: { variants: [] }, args: { variant: 'rtl' as const }, }; export const Button = { ...Default, args: { ...Default.args, controlType: 'button' }, }; export const ButtonAsLink = { ...Default, args: { ...Default.args, controlType: 'buttonAsLink' }, }; export const ButtonPartiallyInteractive = { ...Default, args: { ...Default.args, controlType: 'partialButton' }, }; export const ButtonAsLinkPartiallyInteractive = { ...Default, args: { ...Default.args, controlType: 'partialButtonAsLink' }, }; export const IconButton = { ...Default, args: { ...Default.args, controlType: 'iconButton' }, }; export const IconButtonAsLink = { ...Default, args: { ...Default.args, controlType: 'iconButtonAsLink' }, }; export const IconButtonWithLabel = { ...Default, args: { ...Default.args, controlType: 'iconButtonWithLabel' }, }; export const IconButtonAsLinkWithLabel = { ...Default, args: { ...Default.args, controlType: 'iconButtonAsLinkWithLabel' }, }; export const IconButtonPartiallyInteractive = { ...Default, args: { ...Default.args, controlType: 'partialIconButton' }, }; export const IconButtonAsLinkPartiallyInteractive = { ...Default, args: { ...Default.args, controlType: 'partialIconButtonAsLink' }, }; export const Navigation = { ...Default, args: { ...Default.args, controlType: 'navigation' }, }; export const NavigationAsButton = { ...Default, args: { ...Default.args, controlType: 'navigationAsButton' }, }; export const Checkbox = { ...Default, args: { ...Default.args, controlType: 'checkbox' }, }; export const Radio = { ...Default, args: { ...Default.args, controlType: 'radio' }, }; export const Switch = { ...Default, args: { ...Default.args, controlType: 'switch' }, }; export const NonInteractive = { ...Default, args: { ...Default.args, controlType: 'non-interactive' }, };