Skip to content

Commit

Permalink
feat(website): migrate the legends guide to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Dec 26, 2021
1 parent 1f4f480 commit c3d7609
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 33 deletions.
4 changes: 1 addition & 3 deletions website/src/components/guides/axes/AxesLegend.tsx
Expand Up @@ -11,7 +11,7 @@ import { useAxisTheme } from './theme'

const axisPositions = ['start', 'middle', 'end'] as const

const AxesLegend = () => {
export const AxesLegend = () => {
const theme = useAxisTheme()

return (
Expand Down Expand Up @@ -76,5 +76,3 @@ const AxesLegend = () => {
</>
)
}

export default AxesLegend
4 changes: 1 addition & 3 deletions website/src/components/guides/axes/AxesPosition.tsx
Expand Up @@ -9,7 +9,7 @@ import { linearXScale, linearYScale } from './scales'
import { FullWidthBanner, DescriptionBlock } from '../../styled'
import { useAxisTheme } from './theme'

const AxesPosition = () => {
export const AxesPosition = () => {
const theme = useAxisTheme()

return (
Expand Down Expand Up @@ -62,5 +62,3 @@ const AxesPosition = () => {
</>
)
}

export default AxesPosition
4 changes: 1 addition & 3 deletions website/src/components/guides/axes/AxesTicks.tsx
Expand Up @@ -9,7 +9,7 @@ import { linearXScale, pointXScale, timeXScale, timeXScaleHours } from './scales
import { FullWidthBanner, DescriptionBlock } from '../../styled'
import { useAxisTheme } from './theme'

const AxesTicks = () => {
export const AxesTicks = () => {
const theme = useAxisTheme()

return (
Expand Down Expand Up @@ -153,5 +153,3 @@ const AxesTicks = () => {
</>
)
}

export default AxesTicks
3 changes: 3 additions & 0 deletions website/src/components/guides/axes/index.ts
@@ -0,0 +1,3 @@
export * from './AxesLegend'
export * from './AxesPosition'
export * from './AxesTicks'
Expand Up @@ -9,7 +9,7 @@ const legendProps = {
itemHeight: 24,
}

const LegendDirection = () => {
export const LegendDirection = () => {
const theme = useTheme()

return (
Expand Down Expand Up @@ -47,5 +47,3 @@ const LegendDirection = () => {
</div>
)
}

export default LegendDirection
Expand Up @@ -2,9 +2,9 @@ import React from 'react'
import { LegendSvgItem } from '@nivo/legends'
import { useTheme } from '../../../theming/context'

const itemDirections = ['left-to-right', 'right-to-left', 'top-to-bottom', 'bottom-to-top']
const itemDirections = ['left-to-right', 'right-to-left', 'top-to-bottom', 'bottom-to-top'] as const

const LegendItemDirection = () => {
export const LegendItemDirection = () => {
const theme = useTheme()

const itemsProps = {
Expand Down Expand Up @@ -96,5 +96,3 @@ const LegendItemDirection = () => {
</div>
)
}

export default LegendItemDirection
Expand Up @@ -13,7 +13,7 @@ const anchors = [
'bottom-left',
'left',
'center',
]
] as const

const translateExamples = [
{
Expand Down Expand Up @@ -48,7 +48,7 @@ const legendProps = {
direction: 'column',
}

const LegendPosition = () => {
export const LegendPosition = () => {
const theme = useTheme()

return (
Expand Down Expand Up @@ -177,5 +177,3 @@ const LegendPosition = () => {
</div>
)
}

export default LegendPosition
Expand Up @@ -3,7 +3,7 @@ import { LegendSvgItem } from '@nivo/legends'
import { Highlight } from '../../Highlight'
import { useTheme } from '../../../theming/context'

const shapes = ['square', 'circle', 'triangle', 'diamond']
const shapes = ['square', 'circle', 'triangle', 'diamond'] as const

const code = `
const CustomSymbolShape = ({
Expand All @@ -23,7 +23,7 @@ const CustomSymbolShape = ({
)
`.trim()

const SymbolShape = () => {
export const SymbolShape = () => {
const theme = useTheme()

const itemsProps = {
Expand Down Expand Up @@ -82,5 +82,3 @@ const SymbolShape = () => {
</div>
)
}

export default SymbolShape
4 changes: 4 additions & 0 deletions website/src/components/guides/legends/index.ts
@@ -0,0 +1,4 @@
export * from './LegendDirection'
export * from './LegendItemDirection'
export * from './LegendPosition'
export * from './SymbolShape'
6 changes: 2 additions & 4 deletions website/src/pages/guides/axes.tsx
Expand Up @@ -3,15 +3,13 @@ import { Link } from 'gatsby'
import Layout from '../../components/Layout'
import { Seo } from '../../components/Seo'
import PageContent from '../../components/PageContent'
import AxesPosition from '../../components/guides/axes/AxesPosition'
import AxesTicks from '../../components/guides/axes/AxesTicks'
import AxesLegend from '../../components/guides/axes/AxesLegend'
import { AxesPosition, AxesTicks, AxesLegend } from '../../components/guides/axes'
import { DescriptionBlock } from '../../components/styled'

const AxesGuide = () => {
return (
<Layout>
<Seo title="Axes Guide" />
<Seo title="Axes Guide" description="Using chart axes in nivo components." />
<PageContent>
<div className="guide__header">
<h1>Axes</h1>
Expand Down
13 changes: 8 additions & 5 deletions website/src/pages/guides/legends.tsx
@@ -1,13 +1,16 @@
import React from 'react'
// @ts-ignore
import { themeContext } from '@nivo/core'
import { useTheme } from '../../theming/context'
import Layout from '../../components/Layout'
import { Seo } from '../../components/Seo'
import PageContent from '../../components/PageContent'
import LegendPosition from '../../components/guides/legends/LegendPosition'
import LegendDirection from '../../components/guides/legends/LegendDirection'
import LegendItemDirection from '../../components/guides/legends/LegendItemDirection'
import SymbolShape from '../../components/guides/legends/SymbolShape'
import {
LegendPosition,
LegendDirection,
LegendItemDirection,
SymbolShape,
} from '../../components/guides/legends'
import { DescriptionBlock } from '../../components/styled'

const Legends = () => {
Expand All @@ -16,7 +19,7 @@ const Legends = () => {
return (
<Layout>
<themeContext.Provider value={theme.nivo}>
<Seo title="Legends Guide" />
<Seo title="Legends Guide" description="How to add legends to your nivo charts?" />
<PageContent>
<div className="guide__header">
<h1>Legends</h1>
Expand Down

0 comments on commit c3d7609

Please sign in to comment.