forked from mantinedev/mantine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add legend and tooltip formatter demos
- Loading branch information
1 parent
114be9d
commit 182d4a3
Showing
12 changed files
with
500 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/@docs/demos/src/demos/charts/AreaChart/AreaChart.demo.legendFormatter.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,78 @@ | ||
import React from 'react'; | ||
import { AreaChart } from '@mantine/charts'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
import { data, dataCode } from './_data'; | ||
|
||
const code = ` | ||
import { AreaChart } from '@mantine/charts'; | ||
import { data } from './data'; | ||
function Demo() { | ||
return ( | ||
<AreaChart | ||
h={300} | ||
data={data} | ||
dataKey="date" | ||
withLegend | ||
legendProps={{ | ||
formatter: (value) => { | ||
switch (value) { | ||
case 'Apples': | ||
return <>🍏</>; | ||
case 'Oranges': | ||
return <>🍊</>; | ||
case 'Tomatoes': | ||
return <>🍅</>; | ||
default: | ||
return <>{value}</>; | ||
} | ||
}, | ||
}} | ||
series={[ | ||
{ name: 'Apples', color: 'indigo.6' }, | ||
{ name: 'Oranges', color: 'blue.6' }, | ||
{ name: 'Tomatoes', color: 'teal.6' }, | ||
]} | ||
/> | ||
); | ||
} | ||
`; | ||
|
||
function Demo() { | ||
return ( | ||
<AreaChart | ||
h={300} | ||
data={data} | ||
dataKey="date" | ||
withLegend | ||
legendProps={{ | ||
formatter: (value) => { | ||
switch (value) { | ||
case 'Apples': | ||
return <>🍏</>; | ||
case 'Oranges': | ||
return <>🍊</>; | ||
case 'Tomatoes': | ||
return <>🍅</>; | ||
default: | ||
return <>{value}</>; | ||
} | ||
}, | ||
}} | ||
series={[ | ||
{ name: 'Apples', color: 'indigo.6' }, | ||
{ name: 'Oranges', color: 'blue.6' }, | ||
{ name: 'Tomatoes', color: 'teal.6' }, | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
export const legendFormatter: MantineDemo = { | ||
type: 'code', | ||
component: Demo, | ||
code: [ | ||
{ code, language: 'tsx', fileName: 'Demo.tsx' }, | ||
{ code: dataCode, language: 'tsx', fileName: 'data.ts' }, | ||
], | ||
}; |
78 changes: 78 additions & 0 deletions
78
packages/@docs/demos/src/demos/charts/AreaChart/AreaChart.demo.tooltipFormatter.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,78 @@ | ||
import React from 'react'; | ||
import { AreaChart } from '@mantine/charts'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
import { data, dataCode } from './_data'; | ||
|
||
const code = ` | ||
import { AreaChart } from '@mantine/charts'; | ||
import { data } from './data'; | ||
function Demo() { | ||
return ( | ||
<AreaChart | ||
h={300} | ||
data={data} | ||
dataKey="date" | ||
type="stacked" | ||
series={[ | ||
{ name: 'Apples', color: 'indigo.6' }, | ||
{ name: 'Oranges', color: 'blue.6' }, | ||
{ name: 'Tomatoes', color: 'teal.6' }, | ||
]} | ||
tooltipProps={{ | ||
formatter: (value, name) => { | ||
switch (name) { | ||
case 'Apples': | ||
return [value, <>🍏</>]; | ||
case 'Oranges': | ||
return [value, <>🍊</>]; | ||
case 'Tomatoes': | ||
return [value, <>🍅</>]; | ||
default: | ||
return [value, <>{name}</>]; | ||
} | ||
}, | ||
}} | ||
/> | ||
); | ||
} | ||
`; | ||
|
||
function Demo() { | ||
return ( | ||
<AreaChart | ||
h={300} | ||
data={data} | ||
dataKey="date" | ||
type="stacked" | ||
series={[ | ||
{ name: 'Apples', color: 'indigo.6' }, | ||
{ name: 'Oranges', color: 'blue.6' }, | ||
{ name: 'Tomatoes', color: 'teal.6' }, | ||
]} | ||
tooltipProps={{ | ||
formatter: (value, name) => { | ||
switch (name) { | ||
case 'Apples': | ||
return [value, <>🍏</>]; | ||
case 'Oranges': | ||
return [value, <>🍊</>]; | ||
case 'Tomatoes': | ||
return [value, <>🍅</>]; | ||
default: | ||
return [value, <>{name}</>]; | ||
} | ||
}, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export const tooltipFormatter: MantineDemo = { | ||
type: 'code', | ||
component: Demo, | ||
code: [ | ||
{ code, language: 'tsx', fileName: 'Demo.tsx' }, | ||
{ code: dataCode, language: 'tsx', fileName: 'data.ts' }, | ||
], | ||
}; |
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
78 changes: 78 additions & 0 deletions
78
packages/@docs/demos/src/demos/charts/BarChart/BarChart.demo.legendFormatter.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,78 @@ | ||
import React from 'react'; | ||
import { BarChart } from '@mantine/charts'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
import { data, dataCode } from './_data'; | ||
|
||
const code = ` | ||
import { BarChart } from '@mantine/charts'; | ||
import { data } from './data'; | ||
function Demo() { | ||
return ( | ||
<BarChart | ||
h={300} | ||
data={data} | ||
dataKey="month" | ||
withLegend | ||
legendProps={{ | ||
formatter: (value) => { | ||
switch (value) { | ||
case 'Smartphones': | ||
return <>📱</>; | ||
case 'Laptops': | ||
return <>💻</>; | ||
case 'Tablets': | ||
return <>🖥️</>; | ||
default: | ||
return <>{value}</>; | ||
} | ||
}, | ||
}} | ||
series={[ | ||
{ name: 'Smartphones', color: 'violet.6' }, | ||
{ name: 'Laptops', color: 'blue.6' }, | ||
{ name: 'Tablets', color: 'teal.6' }, | ||
]} | ||
/> | ||
); | ||
} | ||
`; | ||
|
||
function Demo() { | ||
return ( | ||
<BarChart | ||
h={300} | ||
data={data} | ||
dataKey="month" | ||
withLegend | ||
legendProps={{ | ||
formatter: (value) => { | ||
switch (value) { | ||
case 'Smartphones': | ||
return <>📱</>; | ||
case 'Laptops': | ||
return <>💻</>; | ||
case 'Tablets': | ||
return <>🖥️</>; | ||
default: | ||
return <>{value}</>; | ||
} | ||
}, | ||
}} | ||
series={[ | ||
{ name: 'Smartphones', color: 'violet.6' }, | ||
{ name: 'Laptops', color: 'blue.6' }, | ||
{ name: 'Tablets', color: 'teal.6' }, | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
export const legendFormatter: MantineDemo = { | ||
type: 'code', | ||
component: Demo, | ||
code: [ | ||
{ code, language: 'tsx', fileName: 'Demo.tsx' }, | ||
{ code: dataCode, language: 'tsx', fileName: 'data.ts' }, | ||
], | ||
}; |
76 changes: 76 additions & 0 deletions
76
packages/@docs/demos/src/demos/charts/BarChart/BarChart.demo.tooltipFormatter.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,76 @@ | ||
import React from 'react'; | ||
import { BarChart } from '@mantine/charts'; | ||
import { MantineDemo } from '@mantinex/demo'; | ||
import { data, dataCode } from './_data'; | ||
|
||
const code = ` | ||
import { BarChart } from '@mantine/charts'; | ||
import { data } from './data'; | ||
function Demo() { | ||
return ( | ||
<BarChart | ||
h={300} | ||
data={data} | ||
dataKey="month" | ||
series={[ | ||
{ name: 'Smartphones', color: 'violet.6' }, | ||
{ name: 'Laptops', color: 'blue.6' }, | ||
{ name: 'Tablets', color: 'teal.6' }, | ||
]} | ||
tooltipProps={{ | ||
formatter: (value, name) => { | ||
switch (name) { | ||
case 'Smartphones': | ||
return [value, <>📱</>]; | ||
case 'Laptops': | ||
return [value, <>💻</>]; | ||
case 'Tablets': | ||
return [value, <>🖥️</>]; | ||
default: | ||
return [value, <>{name}</>]; | ||
} | ||
}, | ||
}} | ||
/> | ||
); | ||
} | ||
`; | ||
|
||
function Demo() { | ||
return ( | ||
<BarChart | ||
h={300} | ||
data={data} | ||
dataKey="month" | ||
series={[ | ||
{ name: 'Smartphones', color: 'violet.6' }, | ||
{ name: 'Laptops', color: 'blue.6' }, | ||
{ name: 'Tablets', color: 'teal.6' }, | ||
]} | ||
tooltipProps={{ | ||
formatter: (value, name) => { | ||
switch (name) { | ||
case 'Smartphones': | ||
return [value, <>📱</>]; | ||
case 'Laptops': | ||
return [value, <>💻</>]; | ||
case 'Tablets': | ||
return [value, <>🖥️</>]; | ||
default: | ||
return [value, <>{name}</>]; | ||
} | ||
}, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export const tooltipFormatter: MantineDemo = { | ||
type: 'code', | ||
component: Demo, | ||
code: [ | ||
{ code, language: 'tsx', fileName: 'Demo.tsx' }, | ||
{ code: dataCode, language: 'tsx', fileName: 'data.ts' }, | ||
], | ||
}; |
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
Oops, something went wrong.