Skip to content

Commit

Permalink
feat(website): init guide about theming
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Mar 26, 2019
1 parent b98f65a commit 61459b9
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 0 deletions.
8 changes: 8 additions & 0 deletions website/src/SiteMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import Colors from './components/guides/colors/Colors'
import Legends from './components/guides/legends/Legends'
import Gradients from './components/guides/gradients/Gradients'
import Patterns from './components/guides/patterns/Patterns'
import Theming from './components/guides/theming/Theming'
import About from './components/pages/About'
import Faq from './components/pages/Faq'
import Icons from './components/icons/Icons'
Expand Down Expand Up @@ -565,6 +566,13 @@ const SITEMAP = [
component: Patterns,
description: 'Using patterns to fill your charts.',
},
// {
// className: 'theming',
// path: '/guides/theming',
// label: 'Theming',
// component: Theming,
// description: 'Theming nivo charts.',
// },
],
},
{
Expand Down
205 changes: 205 additions & 0 deletions website/src/components/guides/theming/Theming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import React, { useState } from 'react'
import Helmet from 'react-helmet'
import styled from 'styled-components'
import { defaultTheme } from '@nivo/core'
import { ResponsiveBar } from '@nivo/bar'
import { ResponsiveLine } from '@nivo/line'
import ChartControlGroups from '../../controls/ChartControlGroups'

const Container = styled.div`
display: grid;
grid-template-columns: 2fr 1fr;
grid-column-gap: 24px;
`

const initialTheme = {
background: '#ffffff', // defaultTheme.background,
textColor: defaultTheme.textColor,
fontSize: defaultTheme.fontSize,
axis: {
domain: {
line: {
stroke: '#777777', // defaultTheme.axis.domain.line.stroke,
strokeWidth: defaultTheme.axis.domain.line.strokeWidth,
},
},
ticks: {
line: {
stroke: defaultTheme.axis.ticks.line.stroke,
strokeWidth: defaultTheme.axis.ticks.line.strokeWidth,
},
},
},
grid: {
line: {
stroke: defaultTheme.grid.line.stroke,
strokeWidth: defaultTheme.grid.line.strokeWidth,
},
},
}

const controlGroups = [
{
name: 'Global',
controls: [
{
name: 'background',
help: 'main background color.',
type: 'colorPicker',
},
{
name: 'textColor',
help: 'main text color.',
type: 'colorPicker',
},
// fontFamily: 'sans-serif',
{
name: 'fontSize',
help: 'main font size.',
type: 'range',
unit: 'px',
min: 6,
max: 36,
},
],
},
{
name: 'Axis',
controls: [
{
name: 'axis.domain.line.stroke',
type: 'colorPicker',
},
{
name: 'axis.domain.line.strokeWidth',
type: 'range',
unit: 'px',
min: 0,
max: 32,
},
{
name: 'axis.ticks.line.stroke',
type: 'colorPicker',
},
{
name: 'axis.ticks.line.strokeWidth',
type: 'range',
unit: 'px',
min: 0,
max: 32,
},
],
},
{
name: 'Grid',
controls: [
{
name: 'grid.line.stroke',
type: 'colorPicker',
},
{
name: 'grid.line.strokeWidth',
type: 'range',
unit: 'px',
min: 0,
max: 32,
},
],
},
]

const Theming = () => {
const [theme, setTheme] = useState(initialTheme)

return (
<div className="inner-content">
<Helmet title="Theming" />
<div className="page_content">
<div className="guide__header">
<h1 className="page_header">Theming</h1>
</div>
<div className="guide__description text-content">
<p>
nivo supports theming via the <code>theme</code> property, this property
must contain an object which defines various styles to be applied to your
charts. If you don't provide a theme, the default theme will be used. When
you provide a theme, you don't have to provide all properties as it will get
merged with the default theme.
</p>
<p>
There are a few things to notice while theming your components. Values for
font-size, borders… are <strong>unitless</strong> as nivo supports several
implementations (SVG, HTML, Canvas), however you can pass extra CSS
attributes when using a specific implementation, for example, you might add
a stroke-dasharray to the grid lines when using the SVG implementation of
the Bar component, however it will have no effect on BarCanvas as it doesn'r
support it. The theme only drives the base style of the charts, for things
such as symbol colors, patterns, legends, you'll have to use the dedicated
properties.
</p>
<Container>
<div>
<ChartControlGroups
ns="theming"
scope="*"
group="Global"
settings={theme}
onChange={setTheme}
groups={controlGroups}
/>
</div>
<div>
<div style={{ height: 160 }}>
<ResponsiveBar
margin={{
top: 10,
right: 10,
bottom: 30,
left: 30,
}}
data={[
{ id: 'A', value: 12 },
{ id: 'B', value: 17 },
{ id: 'C', value: 9 },
{ id: 'D', value: 15 },
{ id: 'E', value: 23 },
]}
theme={theme}
animate={false}
/>
</div>
<div style={{ height: 160 }}>
<ResponsiveLine
margin={{
top: 10,
right: 10,
bottom: 30,
left: 30,
}}
data={[
{
id: 'default',
data: [
{ x: 'A', y: 12 },
{ x: 'B', y: 17 },
{ x: 'C', y: 9 },
{ x: 'D', y: 15 },
{ x: 'E', y: 23 },
],
},
]}
enableDots={true}
enableDotLabel={true}
theme={theme}
animate={false}
/>
</div>
</div>
</Container>
</div>
</div>
</div>
)
}

export default Theming

0 comments on commit 61459b9

Please sign in to comment.