You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ParameterInput.stories.tsx 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import ParameterInput, { ParameterInputValue } from '@/components/ParameterInput';
  2. import { action } from '@storybook/addon-actions';
  3. import type { Meta, StoryObj } from '@storybook/react';
  4. import { fn } from '@storybook/test';
  5. import { Button } from 'antd';
  6. import { useState } from 'react';
  7. // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
  8. const meta = {
  9. title: 'Components/ParameterInput 参数输入框',
  10. component: ParameterInput,
  11. parameters: {
  12. // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
  13. // layout: 'centered',
  14. },
  15. // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
  16. tags: ['autodocs'],
  17. // More on argTypes: https://storybook.js.org/docs/api/argtypes
  18. argTypes: {
  19. // backgroundColor: { control: 'color' },
  20. },
  21. // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
  22. args: { onChange: fn() },
  23. } satisfies Meta<typeof ParameterInput>;
  24. export default meta;
  25. type Story = StoryObj<typeof meta>;
  26. // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
  27. export const Input: Story = {
  28. args: {
  29. placeholder: '请输入工作目录',
  30. style: { width: 300 },
  31. canInput: true,
  32. textArea: false,
  33. allowClear: true,
  34. size: 'large',
  35. },
  36. };
  37. export const Select: Story = {
  38. args: {
  39. placeholder: '请输入工作目录',
  40. style: { width: 300 },
  41. canInput: true,
  42. size: 'large',
  43. },
  44. render: function Render(args) {
  45. const [value, setValue] = useState<ParameterInputValue | undefined>('');
  46. const onClick = () => {
  47. const value = {
  48. value: 'storybook',
  49. showValue: 'storybook',
  50. fromSelect: true,
  51. otherValue: 'others',
  52. };
  53. setValue(value);
  54. action('onChange')(value);
  55. };
  56. return (
  57. <>
  58. <ParameterInput
  59. {...args}
  60. value={value}
  61. onChange={(value) => {
  62. setValue(value);
  63. action('onChange')(value);
  64. }}
  65. ></ParameterInput>
  66. <Button type="primary" style={{ display: 'block', marginTop: 10 }} onClick={onClick}>
  67. 模拟从全局参数选择
  68. </Button>
  69. </>
  70. );
  71. },
  72. };
  73. export const Ellipse: Story = {
  74. args: {
  75. placeholder: '请输入工作目录',
  76. style: { width: 300 },
  77. canInput: true,
  78. size: 'large',
  79. },
  80. render: function Render(args) {
  81. const [value, setValue] = useState<ParameterInputValue | undefined>('');
  82. const onClick = () => {
  83. const value = {
  84. value: 'storybook',
  85. showValue:
  86. 'storybookstorybookstorybookstorybookstorybookstorybookstorybookstorybookstorybookstorybook',
  87. fromSelect: true,
  88. otherValue: 'others',
  89. };
  90. setValue(value);
  91. action('onChange')(value);
  92. };
  93. return (
  94. <>
  95. <ParameterInput
  96. {...args}
  97. value={value}
  98. onChange={(value) => {
  99. setValue(value);
  100. action('onChange')(value);
  101. }}
  102. ></ParameterInput>
  103. <Button type="primary" style={{ display: 'block', marginTop: 10 }} onClick={onClick}>
  104. 模拟从全局参数选择
  105. </Button>
  106. </>
  107. );
  108. },
  109. };
  110. export const Disabled: Story = {
  111. args: {
  112. placeholder: '请输入工作目录',
  113. style: { width: 300 },
  114. value: {
  115. value: 'storybook',
  116. showValue: 'storybook',
  117. fromSelect: true,
  118. },
  119. canInput: true,
  120. size: 'large',
  121. disabled: true,
  122. },
  123. };