-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Charts: Adding a theme provider (#40558)
* Charts - Adding a Theme provider and themes * Charts - Updating theme objects with colours * Charts - Updating examples * changelog * Charts - Fixing double imports
- Loading branch information
1 parent
a217fd3
commit 6be299d
Showing
12 changed files
with
268 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
Adding a theme provider to Automattic Charts |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { ThemeProvider, useChartTheme } from './theme-provider'; | ||
export { defaultTheme, jetpackTheme, wooTheme } from './themes'; |
131 changes: 131 additions & 0 deletions
131
projects/js-packages/charts/src/providers/theme/stories/index.stories.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,131 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { ThemeProvider, jetpackTheme, wooTheme } from '../.'; | ||
import { LineChart, BarChart, PieSemiCircleChart } from '../../..'; | ||
|
||
const meta: Meta< typeof LineChart > = { | ||
title: 'JS Packages/Charts/Themes', | ||
component: ThemeProvider, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj< typeof ThemeProvider >; | ||
|
||
const sampleData = [ | ||
{ date: new Date( '2024-01-01' ), value: 10, label: 'Jan 1' }, | ||
{ date: new Date( '2024-01-02' ), value: 20, label: 'Jan 2' }, | ||
{ date: new Date( '2024-01-03' ), value: 15, label: 'Jan 3' }, | ||
{ date: new Date( '2024-01-04' ), value: 25, label: 'Jan 4' }, | ||
{ date: new Date( '2024-01-05' ), value: 30, label: 'Jan 5' }, | ||
]; | ||
|
||
const pieData = [ | ||
{ | ||
label: 'Windows', | ||
value: 80000, | ||
valueDisplay: '80K', | ||
percentage: 2, | ||
}, | ||
{ | ||
label: 'MacOS', | ||
value: 30000, | ||
valueDisplay: '30K', | ||
percentage: 5, | ||
}, | ||
{ | ||
label: 'Linux', | ||
value: 22000, | ||
valueDisplay: '22K', | ||
percentage: 1, | ||
}, | ||
]; | ||
|
||
const GridComponent = ( { children } ) => { | ||
return ( | ||
<div style={ { display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: '1rem' } }> | ||
{ children } | ||
</div> | ||
); | ||
}; | ||
|
||
export const Default: Story = { | ||
render: () => ( | ||
<ThemeProvider> | ||
<GridComponent> | ||
<LineChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<BarChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<PieSemiCircleChart | ||
data={ pieData } | ||
width={ 400 } | ||
height={ 200 } | ||
label="Pie Chart" | ||
note="Default Theme" | ||
/> | ||
</GridComponent> | ||
</ThemeProvider> | ||
), | ||
}; | ||
|
||
export const JetpackTheme: Story = { | ||
render: () => ( | ||
<ThemeProvider theme={ jetpackTheme }> | ||
<GridComponent> | ||
<LineChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<BarChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<PieSemiCircleChart | ||
data={ pieData } | ||
width={ 400 } | ||
height={ 200 } | ||
label="Pie Chart" | ||
note="Jetpack Theme" | ||
/> | ||
</GridComponent> | ||
</ThemeProvider> | ||
), | ||
}; | ||
|
||
export const WooTheme: Story = { | ||
render: () => ( | ||
<ThemeProvider theme={ wooTheme }> | ||
<GridComponent> | ||
<LineChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<BarChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<PieSemiCircleChart | ||
data={ pieData } | ||
width={ 400 } | ||
height={ 200 } | ||
label="Pie Chart" | ||
note="Woo Theme" | ||
/> | ||
</GridComponent> | ||
</ThemeProvider> | ||
), | ||
}; | ||
|
||
export const CustomColorTheme: Story = { | ||
render: () => ( | ||
<ThemeProvider | ||
theme={ { | ||
colors: [ '#073B3A', '#0B6E4F', '#08A045', '#6BBF59', '#DDB771' ], | ||
gridStyles: { | ||
stroke: '#ffe3e3', | ||
strokeWidth: 2, | ||
}, | ||
} } | ||
> | ||
<GridComponent> | ||
<LineChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<BarChart data={ sampleData } width={ 400 } height={ 300 } /> | ||
<PieSemiCircleChart | ||
data={ pieData } | ||
width={ 400 } | ||
height={ 200 } | ||
label="Pie Chart" | ||
note="Custom Color Theme" | ||
/> | ||
</GridComponent> | ||
</ThemeProvider> | ||
), | ||
}; |
Oops, something went wrong.