Skip to content

Commit

Permalink
feat: Spin 组件支持全局扩展配置
Browse files Browse the repository at this point in the history
  • Loading branch information
颜宇浩 committed Oct 11, 2024
1 parent 1cabc50 commit ca8f359
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 20 deletions.
17 changes: 16 additions & 1 deletion docs/markdown/shineout/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ setConfig({

用于配置组件默认的 Spin 类型

类型: `spin: string`
类型: `spin: string | {
name: string;
color?: string;
tip?: React.ReactNode;
}`

默认值: `ring`

Expand All @@ -79,6 +83,17 @@ setConfig({
})
```

```js
// 设置全局 Spin 的默认类型、提示内容、颜色
setConfig({
spin: {
name: 'wave',
color: '#000000',
tip: 'loading...'
}
})
```

### 弹出层容器

配置 Modal Popover 等组件的弹出层容器
Expand Down
10 changes: 9 additions & 1 deletion packages/base/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ import { create } from '@shined/reactive';
import { getSnapshot } from '@shined/reactive/vanilla';
import { LanType, Direction } from './locale/Props';

export type SpinConfig =
| string
| {
name: string;
color?: string;
tip?: React.ReactNode;
};

export interface ConfigOption {
prefix: string;
locale: LanType;
delay?: number;
trim?: boolean;
spin?: string;
spin?: SpinConfig;
direction: Direction;
popupContainer?: HTMLElement | null | (() => HTMLElement | null);
}
Expand Down
46 changes: 41 additions & 5 deletions packages/base/src/spin/spin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,51 @@ const Spin = (props: SpinProps = {}) => {
style,
loading,
name: nameProps,
tip,
tip: tipProps,
tipClassName,
color,
color: colorProps,
mode = 'vertical',
} = props;

const config = useConfig();

const name = nameProps ?? config.spin ?? 'default';
const getSpinName = () => {
const { spin } = config;
if (!spin) return;

if (typeof spin === 'string') {
return spin;
}

if (typeof spin === 'object') {
const { name } = spin;
return name;
}

return;
};

const getSpinTip = () => {
const { spin } = config;
if (!spin || typeof spin !== 'object') return;
const { tip } = spin;
return tip;
};

const getSpinColor = () => {
const { spin } = config;
if (!spin || typeof spin !== 'object') return;
const { color } = spin;
return color;
};

const name = nameProps ?? getSpinName() ?? 'default';

const tip = tipProps ?? getSpinTip();

const color = colorProps ?? getSpinColor();

console.log('color', color);

const spinStyle = jssStyle?.spin?.() || ({} as SpinClasses);

Expand All @@ -32,7 +68,7 @@ const Spin = (props: SpinProps = {}) => {
const n = name as keyof typeof Spins;
if (Spins[n]) {
const Comp = Spins[n];
return <Comp {...props} style={style} />;
return <Comp {...props} color={color} style={style} />;
}

return null;
Expand All @@ -47,7 +83,7 @@ const Spin = (props: SpinProps = {}) => {
};

const renderContent = () => {
if ('tip' in props) {
if (tip) {
return (
<div className={contentClass}>
{renderSpin()}
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/chasing-dots.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

const duration = 2;

export default {
Expand All @@ -14,7 +16,7 @@ export default {
height: '60%',
borderRadius: '100%',
animation: `$chasing-dots-2 ${duration}s ease-in-out infinite `,
fill: '#197AFA',
fill: Token.spinColor,

'&:last-child': {
top: 'auto',
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/chasing-ring.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

export default {
position: 'relative',
// margin: 'auto',
Expand All @@ -12,7 +14,7 @@ export default {
border: '1px solid transparent',
borderRadius: '100%',
transformOrigin: '50% 50%',
borderTopColor: '#197AFA',
borderTopColor: Token.spinColor,

'&:nth-child(1)': {
animation: '$chasing-ring-1 2s infinite',
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/cube-grid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

const delayRange = 0.4;

export default {
Expand All @@ -7,7 +9,7 @@ export default {
height: '33.3333%',
float: 'left',
animation: '$cube-grid 1.3s infinite ease-in-out',
background: '#197AFA',
background: Token.spinColor,
boxSizing: 'border-box',
'&:nth-child(1)': { animationDelay: `${delayRange * 0.5}s` },
'&:nth-child(2)': { animationDelay: `${delayRange * 0.75}s` },
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/default.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

const Default = (count = 12) => {
const animationDelay: any = {};

Expand Down Expand Up @@ -27,7 +29,7 @@ const Default = (count = 12) => {
'& div': {
height: '55%',
margin: '0 auto',
background: '#197AFA',
background: Token.spinColor,
borderRadius: 5,
animation: '$keyframesFade 1s infinite ease-in-out both',
},
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/double-bounce.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

export default {
position: 'relative',
// margin: 'auto',
Expand All @@ -11,7 +13,7 @@ export default {
borderRadius: '50%',
opacity: 0.6,
animation: '$double-bounce 2s ease-in-out infinite',
background: '#197AFA',
background: Token.spinColor,

'&:last-child': {
animationDelay: '-1s',
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/fading-circle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

const circleCount = 12;

const loop = () => {
Expand Down Expand Up @@ -32,7 +34,7 @@ export default {
...loop(),
},
'& svg': {
fill: '#197AFA',
fill: Token.spinColor,
animation: '$fading-circle 1.2s infinite ease-in-out both',
},
};
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/four-dots.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

export default {
// margin: 'auto',
position: 'relative',
Expand All @@ -16,7 +18,7 @@ export default {
},

'& svg': {
fill: '#197AFA',
fill: Token.spinColor,
},

'&:nth-child(1)': {
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/plane.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Token from '@sheinx/theme';

export default {
// margin: 'auto',
boxSizing: 'border-box',
animation: '$plane 1s linear infinite',
background: '#197AFA',
background: Token.spinColor,
};
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/pulse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Token from '@sheinx/theme';

export default {
// margin: 'auto',
boxSizing: 'border-box',
borderRadius: '100%',
animation: '$pulse 1s linear infinite',
background: '#197AFA',
background: Token.spinColor,
};
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/ring.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Token from '@sheinx/theme';

export default {
// margin: 'auto',
boxSizing: 'border-box',
position: 'relative',
borderStyle: 'solid',
borderColor: '#197AFA',
borderColor: Token.spinColor,
borderRadius: '50%',
animation: '$ring 1s linear infinite',
borderTopColor: 'transparent',
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/scale-circle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

const circleCount = 12;

const loop = () => {
Expand Down Expand Up @@ -32,7 +34,7 @@ export default {
...loop(),
},
'& svg': {
fill: '#197AFA',
fill: Token.spinColor,
animation: '$scale-circle 1.2s infinite ease-in-out both',
},
};
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/tree-bounce.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

export default {
// margin: 'auto',
textAlign: 'center',
Expand All @@ -10,7 +12,7 @@ export default {
animation: '$three-bounce 1.4s ease-in-out 0s infinite both',

'& svg': {
fill: '#197AFA',
fill: Token.spinColor,
},

'&:nth-child(1)': {
Expand Down
4 changes: 3 additions & 1 deletion packages/shineout-style/src/spin/wave.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Token from '@sheinx/theme';

const loop = (count = 5) => {
const animationDelay: any = {};
for (let i = 1; i < count; i++) {
Expand All @@ -18,7 +20,7 @@ export default {
display: 'inline-block',
height: '100%',
marginRight: '2px',
background: '#197AFA',
background: Token.spinColor,
animation: '$wave 1.2s infinite ease-in-out',

':last-child': {
Expand Down
1 change: 1 addition & 0 deletions packages/theme/src/spin/spin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const spinTokens: SpinTokens = {
spinTipFontColor: 'Brand-6',
spinVerticalMargin: 'Spacing-4',
spinHorizontalMargin: 'Spacing-4',
spinColor: 'Brand-6',
spinBackgroundColor: 'Neutral-fill-1',
};

Expand Down
1 change: 1 addition & 0 deletions packages/theme/src/spin/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const spinTokenExtraValue = {
tip: { font: { color: 'Brand-6' } },
vertical: { margin: 'Spacing-4' },
horizontal: { margin: 'Spacing-4' },
color: 'Brand-6',
background: { color: 'Neutral-fill-1' },
};

Expand Down
6 changes: 6 additions & 0 deletions packages/theme/src/spin/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface SpinTokens {
* @description 加载动画水平模式下与提示文字的外边距
*/
spinHorizontalMargin: string;
/**
* @type {string}
* @token Brand-6
* @description 加载动画颜色
*/
spinColor: string;
/**
* @type {string}
* @token Neutral-fill-1
Expand Down

0 comments on commit ca8f359

Please sign in to comment.