Skip to content

Commit

Permalink
Merge branch 'master' of github.com:oceanbase/oceanbase-design into h…
Browse files Browse the repository at this point in the history
…jg-dev
  • Loading branch information
Vanleehao committed Sep 12, 2023
2 parents 5754291 + 8ac1f06 commit f3a628c
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,36 @@ exports[`ConfigProvider spin spin.indicator should work 1`] = `
</div>
</div>
`;

exports[`ConfigProvider spin spin.indicator should work in nested ConfigProvider 1`] = `
<div
class="ant-app"
>
<div
class="ant-app"
>
<div
aria-busy="true"
aria-live="polite"
class="ant-spin ant-spin-spinning"
>
<div
class="custom-indicator-1 ant-spin-dot"
/>
</div>
</div>
<div
class="ant-app"
>
<div
aria-busy="true"
aria-live="polite"
class="ant-spin ant-spin-spinning"
>
<div
class="custom-indicator-2 ant-spin-dot"
/>
</div>
</div>
</div>
`;
42 changes: 42 additions & 0 deletions packages/design/src/config-provider/__tests__/navigate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,46 @@ describe('ConfigProvider navigate', () => {
);
render(<Demo />);
});

it('navigate should work in nested ConfigProvider', () => {
const SubChild1 = () => {
const { navigate } = useContext(ConfigProvider.ExtendedConfigContext);
expect(typeof navigate).toBe('function');
return <div />;
};
const SubChild2 = () => {
const { navigate } = useContext(ConfigProvider.ExtendedConfigContext);
expect(navigate).toBe(null);
return <div />;
};
const Child = () => {
const { navigate } = useContext(ConfigProvider.ExtendedConfigContext);
expect(typeof navigate).toBe('function');
return (
<>
<ConfigProvider>
<SubChild1 />
</ConfigProvider>
<ConfigProvider navigate={null}>
<SubChild2 />
</ConfigProvider>
</>
);
};
const Parent = () => {
const navigate = useNavigate();
return (
<ConfigProvider navigate={navigate}>
<Child />
</ConfigProvider>
);
};
const Demo = () => (
// useNavigate() may be used only in the context of a <Router> component
<BrowserRouter>
<Parent />
</BrowserRouter>
);
render(<Demo />);
});
});
25 changes: 25 additions & 0 deletions packages/design/src/config-provider/__tests__/spin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,29 @@ describe('ConfigProvider spin', () => {
expect(container.querySelector('.ant-spin-oceanbase')).toBeFalsy();
expect(asFragment().firstChild).toMatchSnapshot();
});

it('spin.indicator should work in nested ConfigProvider', () => {
const { container, asFragment } = render(
<ConfigProvider
spin={{
indicator: <div className="custom-indicator-1" />,
}}
>
<ConfigProvider>
<Spin />
</ConfigProvider>
<ConfigProvider
spin={{
indicator: <div className="custom-indicator-2" />,
}}
>
<Spin />
</ConfigProvider>
</ConfigProvider>
);
expect(container.querySelectorAll('.custom-indicator-1').length).toBe(1);
expect(container.querySelectorAll('.custom-indicator-2').length).toBe(1);
expect(container.querySelectorAll('.ant-spin-oceanbase').length).toBe(0);
expect(asFragment().firstChild).toMatchSnapshot();
});
});
4 changes: 3 additions & 1 deletion packages/design/src/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const { defaultSeed, components } = defaultTheme;
// ConfigProvider 默认设置主题和内嵌 App,支持 message, notification 和 Modal 等静态方法消费 ConfigProvider 配置
// ref: https://ant.design/components/app-cn
const ConfigProvider = ({ children, theme, navigate, spin, ...restProps }: ConfigProviderProps) => {
// inherit from parent ConfigProvider
const parentContext = React.useContext<ExtendedConfigConsumerProps>(ExtendedConfigContext);
return (
<AntConfigProvider
spin={spin}
Expand Down Expand Up @@ -82,7 +84,7 @@ const ConfigProvider = ({ children, theme, navigate, spin, ...restProps }: Confi
>
<ExtendedConfigContext.Provider
value={{
navigate,
navigate: navigate === undefined ? parentContext.navigate : navigate,
}}
>
<App>
Expand Down
25 changes: 14 additions & 11 deletions packages/design/src/spin/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ const genSizeStyle = (spinDotSize: number, token: SpinToken): CSSObject => {
const spinDotWidth = spinDotSize;
const spinDotHight = spinDotWidth * (295 / 397);
return {
[`${componentCls}-dot`]: {
width: spinDotWidth,
height: spinDotHight,
},
[`${componentCls}-text`]: {
width: spinDotWidth,
color: colorText,
// only work for oceanbase indicator
[`&${componentCls}-oceanbase`]: {
[`${componentCls}-dot`]: {
width: spinDotWidth,
height: spinDotHight,
},
[`${componentCls}-text`]: {
width: spinDotWidth,
color: colorText,
},
},
};
};
Expand All @@ -35,6 +38,7 @@ const genNestedSizeStyle = (spinDotSize: number, token: SpinToken): CSSObject =>
const dotMarginTop = -spinDotHight / 2;
const textPaddingTop = (spinDotHight - fontSize) / 2 + 2;
return {
// only work for oceanbase indicator
[`&${componentCls}-oceanbase`]: {
[`${componentCls}-dot`]: {
marginLeft: dotMarginLeft,
Expand All @@ -53,11 +57,10 @@ const genNestedSizeStyle = (spinDotSize: number, token: SpinToken): CSSObject =>
export const genSpinStyle: GenerateStyle<SpinToken> = (token: SpinToken): CSSObject => {
const { componentCls, spinDotSize, spinDotSizeSM, spinDotSizeLG } = token;
return {
// only work for oceanbase indicator
[`${componentCls}`]: {
[`&-oceanbase`]: genSizeStyle(spinDotSize, token),
[`&-sm&-oceanbase`]: genSizeStyle(spinDotSizeSM, token),
[`&-lg&-oceanbase`]: genSizeStyle(spinDotSizeLG, token),
[`&`]: genSizeStyle(spinDotSize, token),
[`&-sm`]: genSizeStyle(spinDotSizeSM, token),
[`&-lg`]: genSizeStyle(spinDotSizeLG, token),
},
[`${componentCls}-nested-loading`]: {
[`> div > ${componentCls}`]: {
Expand Down

0 comments on commit f3a628c

Please sign in to comment.