diff --git a/ghost/admin-x-settings/src/admin-x-ds/global/Separator.tsx b/ghost/admin-x-settings/src/admin-x-ds/global/Separator.tsx index 70f4e90488..f85d02404e 100644 --- a/ghost/admin-x-settings/src/admin-x-ds/global/Separator.tsx +++ b/ghost/admin-x-settings/src/admin-x-ds/global/Separator.tsx @@ -1,7 +1,11 @@ import React from 'react'; -const Separator: React.FC = () => { - return
; +interface SeparatorProps { + color?: string; +} + +const Separator: React.FC = ({color}) => { + return
; }; export default Separator; \ No newline at end of file diff --git a/ghost/admin-x-settings/src/admin-x-ds/global/TextField.tsx b/ghost/admin-x-settings/src/admin-x-ds/global/TextField.tsx index ae086140df..e34f50b6c2 100644 --- a/ghost/admin-x-settings/src/admin-x-ds/global/TextField.tsx +++ b/ghost/admin-x-settings/src/admin-x-ds/global/TextField.tsx @@ -19,7 +19,7 @@ const TextField: React.FC = ({inputRef, title, value, error, placeho {title && {title}} (
{_story()}
)] +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + args: { + id: 'default-toggle' + } +}; + +export const Checked: Story = { + args: { + id: 'default-toggle', + checked: true + } +}; + +export const Small: Story = { + args: { + id: 'default-toggle', + size: 'sm' + } +}; + +export const Large: Story = { + args: { + id: 'default-toggle', + size: 'lg' + } +}; + +export const WithLabel: Story = { + args: { + id: 'default-toggle', + label: 'Check me' + } +}; + +export const WithLabelAndHint: Story = { + args: { + id: 'default-toggle', + label: 'Check me', + hint: 'But only if you dare' + } +}; + +export const LeftToRight: Story = { + args: { + id: 'default-toggle', + label: 'Check me', + hint: 'But only if you dare', + direction: 'rtl' + } +}; + +export const WithSeparator: Story = { + args: { + id: 'default-toggle', + label: 'Check me', + hint: 'But only if you dare', + direction: 'rtl', + separator: true + } +}; + +export const Error: Story = { + args: { + id: 'default-toggle', + label: 'Check me', + hint: 'But only if you dare', + direction: 'rtl', + error: true, + separator: true + } +}; \ No newline at end of file diff --git a/ghost/admin-x-settings/src/admin-x-ds/global/Toggle.tsx b/ghost/admin-x-settings/src/admin-x-ds/global/Toggle.tsx new file mode 100644 index 0000000000..8ee3f7b8d4 --- /dev/null +++ b/ghost/admin-x-settings/src/admin-x-ds/global/Toggle.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import Separator from './Separator'; + +type ToggleSizes = 'sm' | 'md' | 'lg'; +type ToggleDirections = 'ltr' | 'rtl'; + +interface ToggleProps { + id: string; + color?: string; + checked?: boolean; + disabled?: boolean; + error?: boolean; + size?: ToggleSizes; + label?: React.ReactNode; + separator?: boolean; + direction?: ToggleDirections; + hint?: React.ReactNode; +} + +const Toggle: React.FC = ({id, size, direction, label, hint, separator, error, checked}) => { + let sizeStyles = ''; + let labelStyles = ''; + switch (size) { + case 'sm': + sizeStyles = ' h-3 w-5 after:h-2 after:w-2 checked:after:ml-[1.0rem]'; + labelStyles = 'mt-[-5.5px]'; + break; + + case 'lg': + sizeStyles = ' h-5 w-8 after:h-4 after:w-4 checked:after:ml-[1.4rem]'; + labelStyles = 'mt-[-1px]'; + break; + + default: + sizeStyles = ' min-w-[28px] h-4 w-7 after:h-3 after:w-3 checked:after:ml-[1.4rem]'; + labelStyles = 'mt-[-3px]'; + break; + } + + return ( + <> +
+ + {label && +
+ + {hint && {hint}} +
+ } +
+ {(separator || error) && } + + ); +}; + +export default Toggle; \ No newline at end of file