Skip to content

Commit 7f6a814

Browse files
authored
Merge pull request #63 from Koniverse/issue-10
[Issue-6,9,10] Update file upload, icon components, switch storybook
2 parents 816c04a + 5df4e44 commit 7f6a814

File tree

9 files changed

+152
-17
lines changed

9 files changed

+152
-17
lines changed

components/icon/index.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ export interface SWIconProps {
1414
antDesignIcon?: AntIconType;
1515
weight?: IconWeight;
1616
iconColor?: string;
17+
className?: string;
1718
}
1819

1920
const Icon: React.FC<SWIconProps> = ({
21+
className,
2022
type = 'phosphor',
2123
size,
2224
phosphorIcon: PhosphorIcon,
@@ -31,19 +33,21 @@ const Icon: React.FC<SWIconProps> = ({
3133
}
3234

3335
if (size === 'xs') {
34-
return 12;
36+
return 16;
3537
}
3638
if (size === 'sm') {
37-
return 16;
39+
return 24;
3840
}
3941

40-
return 24;
42+
return 32;
4143
};
4244

45+
const wrapperClass = className ? `anticon ${className}` : 'anticon';
46+
4347
if (type === 'fontAwesome' && fontawesomeIcon) {
4448
return (
4549
<span
46-
className='anticon'
50+
className={wrapperClass}
4751
style={{
4852
fontSize: getIconSize(),
4953
color: iconColor,
@@ -61,7 +65,7 @@ const Icon: React.FC<SWIconProps> = ({
6165
if (type === 'phosphor' && PhosphorIcon) {
6266
return (
6367
<span
64-
className='anticon'
68+
className={wrapperClass}
6569
style={{
6670
fontSize: getIconSize(),
6771
color: iconColor,
@@ -75,6 +79,7 @@ const Icon: React.FC<SWIconProps> = ({
7579
if (type === 'antDesignIcon' && AntDesignIcon) {
7680
return (
7781
<AntDesignIcon
82+
className={className}
7883
style={{
7984
fontSize: getIconSize(),
8085
color: iconColor,

components/switch/stories/switch.stories.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ export default {
88
component: Switch,
99
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
1010
argTypes: {
11-
checked: {
12-
control: 'boolean',
13-
defaultValue: false,
14-
},
1511
disabled: {
1612
control: 'boolean',
1713
defaultValue: false,
@@ -30,12 +26,6 @@ export const Default = Template.bind({});
3026
// More on args: https://storybook.js.org/docs/react/writing-stories/args
3127
Default.args = {};
3228

33-
export const Checked = Template.bind({});
34-
// More on args: https://storybook.js.org/docs/react/writing-stories/args
35-
Checked.args = {
36-
checked: true,
37-
};
38-
3929
export const Loading = Template.bind({});
4030
// More on args: https://storybook.js.org/docs/react/writing-stories/args
4131
Loading.args = {

components/theme/themes/dark/colors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const generateNeutralColorPalettes: GenerateNeutralColorMap = (
5353
colorBorder: getSolidColor(colorBgBase, 26),
5454
colorBorderSecondary: getSolidColor(colorBgBase, 19),
5555

56-
colorBgDefault: colorBgBase,
56+
colorBgDefault: '#0C0C0C',
5757
colorBgSecondary: '#1A1A1A',
5858
colorBgInput: '#252525',
5959
colorBgBorder: '#212121',
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
import type { UploadProps } from './interface';
3+
import Upload from './Upload';
4+
5+
export type SingleFileDraggerProps = Omit<UploadProps, 'type' | 'multiple'>;
6+
7+
const SingleFileDragger = React.forwardRef<unknown, SingleFileDraggerProps>(
8+
({ ...restProps }, ref) => (
9+
<Upload ref={ref} {...restProps} type="single-file-drag" multiple={false} maxCount={1} />
10+
),
11+
);
12+
13+
if (process.env.NODE_ENV !== 'production') {
14+
SingleFileDragger.displayName = 'SingleFileDragger';
15+
}
16+
17+
export default SingleFileDragger;

components/upload/Upload.tsx

+54
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import RcUpload from 'rc-upload';
44
import useMergedState from 'rc-util/lib/hooks/useMergedState';
55
import * as React from 'react';
66
import { flushSync } from 'react-dom';
7+
import { Eraser, UploadSimple } from 'phosphor-react';
78
import { ConfigContext } from '../config-provider';
89
import DisabledContext from '../config-provider/DisabledContext';
910
import LocaleReceiver from '../locale/LocaleReceiver';
@@ -13,13 +14,17 @@ import type { RcFile, ShowUploadListInterface, UploadChangeParam, UploadFile } f
1314
import { UploadProps } from './interface';
1415
import UploadList from './UploadList';
1516
import { file2Obj, getFileItem, removeFileItem, updateFileList } from './utils';
17+
import Icon from '../icon';
1618

1719
import useStyle from './style';
1820

1921
export const LIST_IGNORE = `__LIST_IGNORE_${Date.now()}__`;
2022

2123
export { UploadProps };
2224

25+
// todo: i18n this
26+
const ClickOrDragToReplaceFile = 'Click or Drag to replace file';
27+
2328
const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (props, ref) => {
2429
const {
2530
fileList,
@@ -49,6 +54,8 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
4954
action = '',
5055
accept = '',
5156
supportServerRender = true,
57+
title = 'Drag title',
58+
hint = 'Drag hint',
5259
} = props;
5360

5461
// ===================== Disabled =====================
@@ -416,6 +423,53 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
416423
);
417424
}
418425

426+
if (type === 'single-file-drag') {
427+
const dragCls = classNames(
428+
prefixCls,
429+
`${prefixCls}-drag-single`,
430+
{
431+
'-drag-uploading': mergedFileList.some((file) => file.status === 'uploading'),
432+
'-drag-hover': dragState === 'dragover',
433+
'-disabled': mergedDisabled,
434+
'-uploaded': mergedFileList.length,
435+
},
436+
hashId,
437+
);
438+
439+
return wrapSSR(
440+
<div className={classNames(`${prefixCls}-wrapper`, rtlCls, className, hashId)}>
441+
<div
442+
className={dragCls}
443+
onDrop={onFileDrop}
444+
onDragOver={onFileDrop}
445+
onDragLeave={onFileDrop}
446+
>
447+
<RcUpload {...rcUploadProps} ref={upload} className={`${prefixCls}-btn`}>
448+
<div className={`${prefixCls}-drag-container`}>
449+
{!mergedFileList.length ? (
450+
<>
451+
<Icon
452+
type='phosphor'
453+
phosphorIcon={UploadSimple}
454+
className='ant-upload-drag__icon'
455+
/>
456+
<div className={`${prefixCls}-drag__title`}>{title}</div>
457+
<div className={`${prefixCls}-drag__hint`}>{hint}</div>
458+
</>
459+
) : (
460+
<>
461+
<Icon type='phosphor' phosphorIcon={Eraser} className='ant-upload-drag__icon' />
462+
<div className={`${prefixCls}-drag__title`}>{ClickOrDragToReplaceFile}</div>
463+
<div className={`${prefixCls}-drag__hint`}>{mergedFileList[0].name}</div>
464+
</>
465+
)}
466+
</div>
467+
</RcUpload>
468+
</div>
469+
</div>,
470+
);
471+
}
472+
419473
const uploadButtonCls = classNames(prefixCls, `${prefixCls}-select`, {
420474
[`${prefixCls}-disabled`]: mergedDisabled,
421475
});

components/upload/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Dragger from './Dragger';
2+
import SingleFileDragger from './SingleFileDragger';
23
import type { UploadProps } from './Upload';
34
import InternalUpload, { LIST_IGNORE } from './Upload';
45

@@ -17,11 +18,13 @@ type CompoundedComponent<T = any> = InternalUploadType & {
1718
props: React.PropsWithChildren<UploadProps<U>> & React.RefAttributes<any>,
1819
): React.ReactElement;
1920
Dragger: typeof Dragger;
21+
SingleFileDragger: typeof SingleFileDragger;
2022
LIST_IGNORE: string;
2123
};
2224

2325
const Upload = InternalUpload as CompoundedComponent;
2426
Upload.Dragger = Dragger;
27+
Upload.SingleFileDragger = SingleFileDragger;
2528
Upload.LIST_IGNORE = LIST_IGNORE;
2629

2730
export default Upload;

components/upload/interface.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface UploadLocale {
6565
previewFile?: string;
6666
}
6767

68-
export type UploadType = 'drag' | 'select';
68+
export type UploadType = 'single-file-drag' | 'drag' | 'select';
6969
export type UploadListType = 'text' | 'picture' | 'picture-card';
7070
export type UploadListProgressProps = Omit<ProgressProps, 'percent' | 'type'>;
7171

@@ -89,6 +89,8 @@ type BeforeUploadValueType = void | boolean | string | Blob | File;
8989
export interface UploadProps<T = any> extends Pick<RcUploadProps, 'capture'> {
9090
type?: UploadType;
9191
name?: string;
92+
title?: string;
93+
hint?: string;
9294
defaultFileList?: Array<UploadFile<T>>;
9395
fileList?: Array<UploadFile<T>>;
9496
action?: string | ((file: RcFile) => string) | ((file: RcFile) => PromiseLike<string>);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
3+
import Upload from '..';
4+
5+
const { SingleFileDragger } = Upload;
6+
7+
export default {
8+
title: 'Core/SingleFileDragger',
9+
component: SingleFileDragger,
10+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
11+
argTypes: {},
12+
} as ComponentMeta<typeof SingleFileDragger>;
13+
14+
const Template: ComponentStory<typeof SingleFileDragger> = (args) => (
15+
<SingleFileDragger {...args} />
16+
);
17+
18+
export const Default = Template.bind({});
19+
Default.args = {
20+
title: 'Import from Polkadot.js',
21+
hint: 'Please drag an drop the .json file you exported from Polkadot.js',
22+
};

components/upload/style/dragger.ts

+42
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,48 @@ const genDraggerStyle: GenerateStyle<UploadToken> = (token) => {
7070
},
7171
},
7272
},
73+
[`${componentCls}-drag-single`]: {
74+
textAlign: 'center',
75+
cursor: 'pointer',
76+
background: token.colorBgSecondary,
77+
border: `2px dotted ${token.colorBgDivider}`,
78+
transition: `border-color ${token.motionDurationSlow}`,
79+
borderRadius: token.borderRadiusLG,
80+
padding: '32px 16px 10px 16px',
81+
82+
[`${componentCls}-btn`]: {
83+
display: 'block',
84+
outline: 'none',
85+
},
86+
[`${componentCls}-drag__icon`]: {
87+
fontSize: 32,
88+
marginBottom: 8,
89+
},
90+
[`${componentCls}-drag__title`]: {
91+
fontWeight: '600',
92+
marginBottom: 8,
93+
},
94+
[`${componentCls}-drag__hint`]: {
95+
fontWeight: '500',
96+
color: token.colorTextLight4,
97+
wordBreak: 'break-word',
98+
},
99+
'&.-drag-hover': {
100+
paddingBottom: 32,
101+
borderColor: token['geekblue-6'],
102+
},
103+
'&.-uploaded': {
104+
paddingBottom: 32,
105+
106+
[`${componentCls}-drag__icon`]: {
107+
color: token.colorWarning,
108+
},
109+
},
110+
111+
'&:hover': {
112+
borderColor: token['geekblue-4'],
113+
},
114+
},
73115
};
74116
};
75117

0 commit comments

Comments
 (0)