signal-desktop/ts/components/Input.stories.tsx

133 lines
2.8 KiB
TypeScript
Raw Normal View History

// Copyright 2021-2022 Signal Messenger, LLC
2021-07-19 19:26:06 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useState } from 'react';
import { text } from '@storybook/addon-knobs';
import { action } from '@storybook/addon-actions';
import type { PropsType } from './Input';
import { Input } from './Input';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2021-07-19 19:26:06 +00:00
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Input',
};
2021-07-19 19:26:06 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
disabled: Boolean(overrideProps.disabled),
disableSpellcheck: overrideProps.disableSpellcheck,
2021-07-19 19:26:06 +00:00
expandable: Boolean(overrideProps.expandable),
hasClearButton: Boolean(overrideProps.hasClearButton),
i18n,
icon: overrideProps.icon,
maxLengthCount: overrideProps.maxLengthCount,
2021-07-19 19:26:06 +00:00
onChange: action('onChange'),
placeholder: text(
'placeholder',
overrideProps.placeholder || 'Enter some text here'
),
value: text('value', overrideProps.value || ''),
whenToShowRemainingCount: overrideProps.whenToShowRemainingCount,
});
function Controller(props: PropsType): JSX.Element {
const { value: initialValue } = props;
const [value, setValue] = useState(initialValue);
return <Input {...props} onChange={setValue} value={value} />;
}
2022-06-07 00:48:02 +00:00
export const Simple = (): JSX.Element => <Controller {...createProps()} />;
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
export const HasClearButton = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<Controller
{...createProps({
hasClearButton: true,
})}
/>
2022-06-07 00:48:02 +00:00
);
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
HasClearButton.story = {
name: 'hasClearButton',
};
export const CharacterCount = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<Controller
{...createProps({
maxLengthCount: 10,
2021-07-19 19:26:06 +00:00
})}
/>
2022-06-07 00:48:02 +00:00
);
CharacterCount.story = {
name: 'character count',
};
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
export const CharacterCountCustomizableShow = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<Controller
{...createProps({
maxLengthCount: 64,
2021-07-19 19:26:06 +00:00
whenToShowRemainingCount: 32,
})}
/>
2022-06-07 00:48:02 +00:00
);
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
CharacterCountCustomizableShow.story = {
name: 'character count (customizable show)',
};
export const Expandable = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<Controller
{...createProps({
expandable: true,
})}
/>
2022-06-07 00:48:02 +00:00
);
Expandable.story = {
name: 'expandable',
};
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
export const ExpandableWCount = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<Controller
{...createProps({
expandable: true,
hasClearButton: true,
maxLengthCount: 140,
2021-07-19 19:26:06 +00:00
whenToShowRemainingCount: 0,
})}
/>
2022-06-07 00:48:02 +00:00
);
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
ExpandableWCount.story = {
name: 'expandable w/count',
};
export const Disabled = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<Controller
{...createProps({
disabled: true,
})}
/>
2022-06-07 00:48:02 +00:00
);
Disabled.story = {
name: 'disabled',
};
2022-06-07 00:48:02 +00:00
export const SpellcheckDisabled = (): JSX.Element => (
<Controller
{...createProps({
disableSpellcheck: true,
})}
/>
2022-06-07 00:48:02 +00:00
);
SpellcheckDisabled.story = {
name: 'spellcheck disabled',
};