From bf8818e41389b9a8dbf72991e2176e5c1bbb5320 Mon Sep 17 00:00:00 2001 From: zhouyun1 Date: Thu, 14 Sep 2023 15:31:21 +0800 Subject: [PATCH] fix: stories code standard --- .../stories/multiply-line.stories.tsx | 2 +- packages/ui/form/stories/cascade.stories.tsx | 3 +- .../ui/form/stories/get-values.stories.tsx | 5 +- .../ui/form/stories/nested-field.stories.tsx | 5 +- .../ui/form/stories/set-values.stories.tsx | 5 +- .../form/stories/validate-field.stories.tsx | 15 +- packages/ui/form/stories/validate.stories.tsx | 9 +- packages/ui/message/stories/type.stories.tsx | 2 +- .../ui/scrollbar/stories/event.stories.tsx | 2 +- .../table/stories/custom-filter.stories.tsx | 237 +++++++++--------- .../ui/table/stories/data-source.stories.tsx | 2 +- .../table/stories/expanded-render.stories.tsx | 2 +- .../upload/stories/action-render.stories.tsx | 2 +- packages/ui/upload/stories/avatar.stories.tsx | 2 +- packages/ui/upload/stories/photo.stories.tsx | 2 +- 15 files changed, 143 insertions(+), 152 deletions(-) diff --git a/packages/ui/ellipsis-tooltip/stories/multiply-line.stories.tsx b/packages/ui/ellipsis-tooltip/stories/multiply-line.stories.tsx index d6408ba8f..620305f6a 100644 --- a/packages/ui/ellipsis-tooltip/stories/multiply-line.stories.tsx +++ b/packages/ui/ellipsis-tooltip/stories/multiply-line.stories.tsx @@ -6,7 +6,7 @@ import EllipsisTooltip from '../src' */ export const MultiplyLine = () => { const textOverview = - '【译】孔子说:“学习并且不断温习,不也很愉快吗?远方来了朋友,不也很快乐吗?人家不了解我,我也不怨恨,不也是君子吗?”,【译】孔子说:“学习并且不断温习,不也很愉快吗?远方来了朋友,不也很快乐吗?人家不了解我,我也不怨恨,不也是君子吗?”' + '【译】孔子说:“学习并且不断温习,不也很愉快吗?远方来了朋友,不也很快乐吗?人家不了解我,我也不怨恨,不也是君子吗?”,【译】孔子说:“学习并且不断温习,不也很愉快吗?远方来了朋友,不也很快乐吗?人家不了解我,我也不怨恨,不也是君子吗?”' return ( <> diff --git a/packages/ui/form/stories/cascade.stories.tsx b/packages/ui/form/stories/cascade.stories.tsx index fc387006c..8e8ccc82e 100644 --- a/packages/ui/form/stories/cascade.stories.tsx +++ b/packages/ui/form/stories/cascade.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable node/no-callback-literal */ import React from 'react' import Form, { FormHelpers } from '../src' import Button from '@hi-ui/button' @@ -201,7 +200,7 @@ export const Cascade = () => { }} onRemove={(file, fileList, index) => { console.log('remove callback', file, fileList, index) - return new Promise((resolve, reject) => resolve(true)) + return new Promise((resolve) => resolve(true)) }} name={'files[]'} defaultFileList={[ diff --git a/packages/ui/form/stories/get-values.stories.tsx b/packages/ui/form/stories/get-values.stories.tsx index 3e760b770..f087fa8e7 100644 --- a/packages/ui/form/stories/get-values.stories.tsx +++ b/packages/ui/form/stories/get-values.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable node/no-callback-literal */ import React from 'react' import Form, { FormHelpers } from '../src' import Input from '@hi-ui/input' @@ -37,9 +36,9 @@ export const GetValues = () => { validator: (rule, value, callback) => { const telReg = /^[1][3|4|5|6|7|8|9][0-9]{9}$/ if (!value) { - callback('请输入手机号') + callback(new Error('请输入手机号')) } else if (!telReg.test(value)) { - callback('请输入正确的手机号') + callback(new Error('请输入正确的手机号')) } else { callback() } diff --git a/packages/ui/form/stories/nested-field.stories.tsx b/packages/ui/form/stories/nested-field.stories.tsx index d04e4d02c..b2c7625e4 100644 --- a/packages/ui/form/stories/nested-field.stories.tsx +++ b/packages/ui/form/stories/nested-field.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable node/no-callback-literal */ import React from 'react' import Form, { FormHelpers } from '../src' import Input from '@hi-ui/input' @@ -44,9 +43,9 @@ export const NestedField = () => { validator: (rule, value, callback) => { const telReg = /^[1][3|4|5|6|7|8|9][0-9]{9}$/ if (!value) { - callback('请输入手机号') + callback(new Error('请输入手机号')) } else if (!telReg.test(value)) { - callback('请输入正确的手机号') + callback(new Error('请输入正确的手机号')) } else { callback() } diff --git a/packages/ui/form/stories/set-values.stories.tsx b/packages/ui/form/stories/set-values.stories.tsx index dd3041aed..fdc14e60b 100644 --- a/packages/ui/form/stories/set-values.stories.tsx +++ b/packages/ui/form/stories/set-values.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable node/no-callback-literal */ import React from 'react' import Form, { FormHelpers } from '../src' import Input from '@hi-ui/input' @@ -51,9 +50,9 @@ export const SetValues = () => { validator: (rule, value, callback) => { const telReg = /^[1][3|4|5|6|7|8|9][0-9]{9}$/ if (!value) { - callback('请输入手机号') + callback(new Error('请输入手机号')) } else if (!telReg.test(value)) { - callback('请输入正确的手机号') + callback(new Error('请输入正确的手机号')) } else { callback() } diff --git a/packages/ui/form/stories/validate-field.stories.tsx b/packages/ui/form/stories/validate-field.stories.tsx index 4a9ccc6e2..20b7ab609 100644 --- a/packages/ui/form/stories/validate-field.stories.tsx +++ b/packages/ui/form/stories/validate-field.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable node/no-callback-literal */ import React from 'react' import Form, { FormHelpers } from '../src' import Input from '@hi-ui/input' @@ -70,9 +69,9 @@ export const ValidateField = () => { const telReg = /^[1][3|4|5|6|7|8|9][0-9]{9}$/ if (!value) { - callback('请输入手机号') + callback(new Error('请输入手机号')) } else if (!telReg.test(value)) { - callback('请输入正确的手机号') + callback(new Error('请输入正确的手机号')) } else { callback() } @@ -94,9 +93,9 @@ export const ValidateField = () => { validator: (rule, value, callback) => { const telReg = /^[0-9]{6}$/ if (!value) { - callback('请输入手机号') + callback(new Error('请输入手机号')) } else if (!telReg.test(value)) { - callback('请输入正确的验证码') + callback(new Error('请输入正确的验证码')) } else { callback() } @@ -135,9 +134,9 @@ export const ValidateField = () => { validator: (rule, value, callback) => { const telReg = /^(?![^a-zA-Z]+$)(?!\D+$).{8,16}$/ if (!value) { - callback('请输入密码') + callback(new Error('请输入密码')) } else if (!telReg.test(value)) { - callback('请输入包括数字和字母、长度8到16位的密码组合') + callback(new Error('请输入包括数字和字母、长度8到16位的密码组合')) } else { callback() } @@ -159,7 +158,7 @@ export const ValidateField = () => { console.log(value, formData.password) if (value !== formData.password) { - callback('两次密码不同') + callback(new Error('两次密码不同')) } else { callback() } diff --git a/packages/ui/form/stories/validate.stories.tsx b/packages/ui/form/stories/validate.stories.tsx index 490d7803f..675b50c66 100644 --- a/packages/ui/form/stories/validate.stories.tsx +++ b/packages/ui/form/stories/validate.stories.tsx @@ -86,13 +86,10 @@ export const Validate = () => { validator: (rule, value, cb) => { const count = +value if (isNaN(count)) { - // eslint-disable-next-line node/no-callback-literal - cb('请输入数字') + cb(new Error('请输入数字')) } else if (count <= 0) { - // eslint-disable-next-line node/no-callback-literal - cb('必须是正数') + cb(new Error('必须是正数')) } else { - // eslint-disable-next-line node/no-callback-literal cb() } }, @@ -155,7 +152,7 @@ export const Validate = () => { { - console.log('change') + console.log('change', id) }} data={cascaderOptions} style={{ width: '100%' }} diff --git a/packages/ui/message/stories/type.stories.tsx b/packages/ui/message/stories/type.stories.tsx index 45ace4493..0f08a30e9 100644 --- a/packages/ui/message/stories/type.stories.tsx +++ b/packages/ui/message/stories/type.stories.tsx @@ -11,7 +11,7 @@ export const Type = () => { return () => { message.open({ title: '问君能有几多愁,恰似一江春水向东流', - type: type, + type, }) } } diff --git a/packages/ui/scrollbar/stories/event.stories.tsx b/packages/ui/scrollbar/stories/event.stories.tsx index 43619e843..9a62c5489 100644 --- a/packages/ui/scrollbar/stories/event.stories.tsx +++ b/packages/ui/scrollbar/stories/event.stories.tsx @@ -23,7 +23,7 @@ export const Event = () => {

x、y滚动事件

console.log('scroll x')} + onScrollX={() => console.log('scroll x')} onScrollY={() => console.log('scroll y')} > {scrollContent} diff --git a/packages/ui/table/stories/custom-filter.stories.tsx b/packages/ui/table/stories/custom-filter.stories.tsx index fda28f460..56f14a9ce 100644 --- a/packages/ui/table/stories/custom-filter.stories.tsx +++ b/packages/ui/table/stories/custom-filter.stories.tsx @@ -9,6 +9,123 @@ import CheckSelect from '@hi-ui/check-select' * @title 自定义过滤 */ export const CustomFilter = () => { + const initialData = React.useRef([ + { + key: '1', + name: 'John Brown', + age: 32, + tel: '0571-22098909', + tel1: '0571-22098909', + tel2: '0571-22098909', + tel3: '0571-22098909', + tel4: '0571-22098909', + tel5: '0571-22098909', + tel6: '0571-22098909', + tel7: '0571-22098909', + tel8: '0571-22098909', + tel9: '0571-22098909', + tel10: '0571-22098909', + tel11: '0571-22098909', + tel12: '0571-22098909', + phone: 18889898989, + address: 'New York No. 1 Lake Park', + }, + { + key: '2', + name: 'Jim Green', + phone: 18889898888, + tel: '0571-22098909', + tel1: '0571-22098909', + tel2: '0571-22098909', + tel3: '0571-22098909', + tel4: '0571-22098909', + tel5: '0571-22098909', + tel6: '0571-22098909', + tel7: '0571-22098909', + tel8: '0571-22098909', + tel9: '0571-22098909', + tel10: '0571-22098909', + tel11: '0571-22098909', + tel12: '0571-22098909', + age: 42, + address: 'London No. 1 Lake Park', + }, + { + key: '3', + name: 'Joe Black', + age: 32, + tel1: '0571-22098909', + tel2: '0571-22098909', + tel3: '0571-22098909', + tel4: '0571-22098909', + tel5: '0571-22098909', + tel6: '0571-22098909', + tel: '0575-22098909', + tel7: '0571-22098909', + tel8: '0571-22098909', + tel9: '0571-22098909', + tel10: '0571-22098909', + tel11: '0571-22098909', + tel12: '0571-22098909', + phone: 18900010002, + address: 'Sidney No. 1 Lake Park', + }, + { + key: '4', + name: 'Jim Red', + age: 18, + tel1: '0571-22098909', + tel2: '0571-22098909', + tel3: '0571-22098909', + tel4: '0571-22098909', + tel5: '0571-22098909', + tel6: '0571-22098909', + tel: '0575-22098909', + tel7: '0571-22098909', + tel8: '0571-22098909', + tel9: '0571-22098909', + tel10: '0571-22098909', + tel11: '0571-22098909', + tel12: '0571-22098909', + phone: 18900010002, + address: 'London No. 2 Lake Park', + }, + { + key: '5', + name: 'Jake White', + age: 18, + tel1: '0571-22098909', + tel2: '0571-22098909', + tel3: '0571-22098909', + tel4: '0571-22098909', + tel5: '0571-22098909', + tel6: '0571-22098909', + tel: '0575-22098909', + tel7: '0571-22098909', + tel8: '0571-22098909', + tel9: '0571-22098909', + tel10: '0571-22098909', + tel11: '0571-22098909', + tel12: '0571-22098909', + phone: 18900010002, + address: 'Dublin No. 2 Lake Park', + }, + ]) + const [data, setData] = React.useState(initialData.current) + const customFilterData = (keyword, label) => { + if (keyword.length > 0) { + setData( + initialData.current.filter((item) => { + return typeof keyword === 'string' + ? item[label].includes(keyword) + : keyword.includes(item[label]) + }) + ) + } else { + setData(initialData.current) + } + } + const [columns] = React.useState([ { title: 'Name', @@ -17,7 +134,7 @@ export const CustomFilter = () => { key: 1, filterDropdownClassName: 'table-customefilter', filterIcon: , - filterDropdown({ columnData, setFilterDropdownVisible }) { + filterDropdown({ setFilterDropdownVisible }) { let keyword = '' return (
@@ -182,124 +299,6 @@ export const CustomFilter = () => { }, ]) - const initialData = React.useRef([ - { - key: '1', - name: 'John Brown', - age: 32, - tel: '0571-22098909', - tel1: '0571-22098909', - tel2: '0571-22098909', - tel3: '0571-22098909', - tel4: '0571-22098909', - tel5: '0571-22098909', - tel6: '0571-22098909', - tel7: '0571-22098909', - tel8: '0571-22098909', - tel9: '0571-22098909', - tel10: '0571-22098909', - tel11: '0571-22098909', - tel12: '0571-22098909', - phone: 18889898989, - address: 'New York No. 1 Lake Park', - }, - { - key: '2', - name: 'Jim Green', - phone: 18889898888, - tel: '0571-22098909', - tel1: '0571-22098909', - tel2: '0571-22098909', - tel3: '0571-22098909', - tel4: '0571-22098909', - tel5: '0571-22098909', - tel6: '0571-22098909', - tel7: '0571-22098909', - tel8: '0571-22098909', - tel9: '0571-22098909', - tel10: '0571-22098909', - tel11: '0571-22098909', - tel12: '0571-22098909', - age: 42, - address: 'London No. 1 Lake Park', - }, - { - key: '3', - name: 'Joe Black', - age: 32, - tel1: '0571-22098909', - tel2: '0571-22098909', - tel3: '0571-22098909', - tel4: '0571-22098909', - tel5: '0571-22098909', - tel6: '0571-22098909', - tel: '0575-22098909', - tel7: '0571-22098909', - tel8: '0571-22098909', - tel9: '0571-22098909', - tel10: '0571-22098909', - tel11: '0571-22098909', - tel12: '0571-22098909', - phone: 18900010002, - address: 'Sidney No. 1 Lake Park', - }, - { - key: '4', - name: 'Jim Red', - age: 18, - tel1: '0571-22098909', - tel2: '0571-22098909', - tel3: '0571-22098909', - tel4: '0571-22098909', - tel5: '0571-22098909', - tel6: '0571-22098909', - tel: '0575-22098909', - tel7: '0571-22098909', - tel8: '0571-22098909', - tel9: '0571-22098909', - tel10: '0571-22098909', - tel11: '0571-22098909', - tel12: '0571-22098909', - phone: 18900010002, - address: 'London No. 2 Lake Park', - }, - { - key: '5', - name: 'Jake White', - age: 18, - tel1: '0571-22098909', - tel2: '0571-22098909', - tel3: '0571-22098909', - tel4: '0571-22098909', - tel5: '0571-22098909', - tel6: '0571-22098909', - tel: '0575-22098909', - tel7: '0571-22098909', - tel8: '0571-22098909', - tel9: '0571-22098909', - tel10: '0571-22098909', - tel11: '0571-22098909', - tel12: '0571-22098909', - phone: 18900010002, - address: 'Dublin No. 2 Lake Park', - }, - ]) - const [data, setData] = React.useState(initialData.current) - - const customFilterData = (keyword, label) => { - if (keyword.length > 0) { - setData( - initialData.current.filter((item) => { - return typeof keyword === 'string' - ? item[label].includes(keyword) - : keyword.includes(item[label]) - }) - ) - } else { - setData(initialData.current) - } - } - return ( <>

CustomFilter for Table

diff --git a/packages/ui/table/stories/data-source.stories.tsx b/packages/ui/table/stories/data-source.stories.tsx index 39cf62005..5f49f867c 100644 --- a/packages/ui/table/stories/data-source.stories.tsx +++ b/packages/ui/table/stories/data-source.stories.tsx @@ -21,7 +21,7 @@ export const DataSource = () => { url: 'https://mife-gallery.test.mi.com/hiui/stores', params: { page: current, - pageSize: pageSize, + pageSize, // searchParams: searchVal, }, transformResponse: (res) => { diff --git a/packages/ui/table/stories/expanded-render.stories.tsx b/packages/ui/table/stories/expanded-render.stories.tsx index d18dbadb2..7ad20cdd1 100644 --- a/packages/ui/table/stories/expanded-render.stories.tsx +++ b/packages/ui/table/stories/expanded-render.stories.tsx @@ -93,7 +93,7 @@ export const ExpandedRender = () => { { + expandedRender={() => { return (
此处是自定义展开渲染内容 diff --git a/packages/ui/upload/stories/action-render.stories.tsx b/packages/ui/upload/stories/action-render.stories.tsx index dc8ea2e1d..a265874a7 100644 --- a/packages/ui/upload/stories/action-render.stories.tsx +++ b/packages/ui/upload/stories/action-render.stories.tsx @@ -34,7 +34,7 @@ export const ActionRender = () => { console.log('upload callback', file, fileList, response) // if(response&&response.status !== 200) return false // 返回 false 则该文件会从列表里删除 }} - actionRender={({ file, index }) => { + actionRender={({ file }) => { return {file.uploadState === 'loading' ? '加载中' : '删除'} }} /> diff --git a/packages/ui/upload/stories/avatar.stories.tsx b/packages/ui/upload/stories/avatar.stories.tsx index 7cdf12d96..c07894349 100644 --- a/packages/ui/upload/stories/avatar.stories.tsx +++ b/packages/ui/upload/stories/avatar.stories.tsx @@ -20,7 +20,7 @@ export const Avatar = () => { }} onRemove={(file, fileList, index) => { console.log('remove callback', file, fileList, index) - return new Promise((resolve, reject) => resolve(true)) + return new Promise((resolve) => resolve(true)) }} name="uploadAvatar" /> diff --git a/packages/ui/upload/stories/photo.stories.tsx b/packages/ui/upload/stories/photo.stories.tsx index 9608c4e15..acf5bd175 100644 --- a/packages/ui/upload/stories/photo.stories.tsx +++ b/packages/ui/upload/stories/photo.stories.tsx @@ -18,7 +18,7 @@ export const Photo = () => { }} onRemove={(file, fileList, index) => { console.log('remove callback', file, fileList, index) - return new Promise((resolve, reject) => resolve(true)) + return new Promise((resolve) => resolve(true)) }} defaultFileList={[ {