-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from oceanbase/dengfuping-dev
feat(charts): Support for theme
- Loading branch information
Showing
34 changed files
with
735 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/charts/src/ChartProvider/__tests__/theme.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { ChartProvider, useTheme } from '@oceanbase/charts'; | ||
|
||
describe('ChartProvider theme', () => { | ||
it('default theme', () => { | ||
const Child = () => { | ||
const themeConfig = useTheme(); | ||
expect(themeConfig.theme).toBe('light'); | ||
expect(themeConfig.defaultColor).toBe('#4C96FF'); | ||
return <div />; | ||
}; | ||
render( | ||
<ChartProvider> | ||
<Child /> | ||
</ChartProvider> | ||
); | ||
}); | ||
|
||
it('light theme', () => { | ||
const Child = () => { | ||
const themeConfig = useTheme(); | ||
expect(themeConfig.theme).toBe('light'); | ||
expect(themeConfig.defaultColor).toBe('#4C96FF'); | ||
return <div />; | ||
}; | ||
render( | ||
<ChartProvider theme="light"> | ||
<Child /> | ||
</ChartProvider> | ||
); | ||
}); | ||
|
||
it('dark theme', () => { | ||
const Child = () => { | ||
const themeConfig = useTheme(); | ||
expect(themeConfig.theme).toBe('dark'); | ||
expect(themeConfig.defaultColor).toBe('#4D97FF'); | ||
return <div />; | ||
}; | ||
render( | ||
<ChartProvider theme="dark"> | ||
<Child /> | ||
</ChartProvider> | ||
); | ||
}); | ||
|
||
it('custom theme config', () => { | ||
const Child = () => { | ||
const themeConfig = useTheme(); | ||
expect(themeConfig.theme).toBe('custom-theme'); | ||
expect(themeConfig.defaultColor).toBe('#ff0000'); | ||
expect(themeConfig.subColor).toBe('#00ff00'); | ||
return <div />; | ||
}; | ||
render( | ||
<ChartProvider | ||
theme={{ theme: 'custom-theme', defaultColor: '#ff0000', subColor: '#00ff00' }} | ||
> | ||
<Child /> | ||
</ChartProvider> | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
export type Theme = 'light' | 'dark' | string | object; | ||
|
||
export interface ChartConsumerProps { | ||
theme?: Theme; | ||
} | ||
|
||
export const ChartContext = React.createContext<ChartConsumerProps>({ | ||
theme: 'light', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { ChartContext } from './context'; | ||
import type { ChartConsumerProps } from './context'; | ||
|
||
export * from './context'; | ||
|
||
export interface ChartProviderProps extends ChartConsumerProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
const ChartProvider: React.FC<ChartProviderProps> & { | ||
ChartContext: typeof ChartContext; | ||
} = ({ children, theme = 'light', ...restProps }) => { | ||
return ( | ||
<ChartContext.Provider | ||
value={{ | ||
theme, | ||
...restProps, | ||
}} | ||
> | ||
{children} | ||
</ChartContext.Provider> | ||
); | ||
}; | ||
|
||
ChartProvider.ChartContext = ChartContext; | ||
|
||
export default ChartProvider; |
Oops, something went wrong.