From adb73f55676b8697ac4e8001c076bd2f31923f4b Mon Sep 17 00:00:00 2001 From: Laura buns Date: Fri, 17 Jan 2020 00:58:32 +0000 Subject: [PATCH] feat(graphiql-theming): Toolbar component (#1203) by @walaura * separate dividers for the toolbar * add toolbar * add layout to stories Authored-by @walaura --- packages/graphiql/.storybook/decorators.js | 9 + .../src/new-components/Layout.stories.js | 2 +- .../src/new-components/{ => List}/List.js | 6 +- .../new-components/{ => List}/List.stories.js | 26 +- packages/graphiql/src/new-components/Tabs.js | 77 -- .../src/new-components/Toolbar/Content.js | 13 + .../src/new-components/Toolbar/Tabs.js | 48 + .../{ => Toolbar}/Tabs.stories.js | 17 +- .../src/new-components/Toolbar/Toolbar.js | 34 + .../new-components/Toolbar/Toolbar.stories.js | 80 ++ .../Toolbar/support/WithDividers.js | 65 ++ .../src/new-components/Type.stories.js | 11 +- .../__snapshots__/stories.spec.js.snap | 1007 ++++++++++++++--- .../new-components/themes/default/index.js | 11 +- 14 files changed, 1157 insertions(+), 249 deletions(-) create mode 100644 packages/graphiql/.storybook/decorators.js rename packages/graphiql/src/new-components/{ => List}/List.js (78%) rename packages/graphiql/src/new-components/{ => List}/List.stories.js (57%) delete mode 100644 packages/graphiql/src/new-components/Tabs.js create mode 100644 packages/graphiql/src/new-components/Toolbar/Content.js create mode 100644 packages/graphiql/src/new-components/Toolbar/Tabs.js rename packages/graphiql/src/new-components/{ => Toolbar}/Tabs.stories.js (63%) create mode 100644 packages/graphiql/src/new-components/Toolbar/Toolbar.js create mode 100644 packages/graphiql/src/new-components/Toolbar/Toolbar.stories.js create mode 100644 packages/graphiql/src/new-components/Toolbar/support/WithDividers.js diff --git a/packages/graphiql/.storybook/decorators.js b/packages/graphiql/.storybook/decorators.js new file mode 100644 index 00000000000..7464d690ea6 --- /dev/null +++ b/packages/graphiql/.storybook/decorators.js @@ -0,0 +1,9 @@ +import React from 'react'; + +const styles = { + maxWidth: '60em', + margin: '5em auto', + border: '1px solid #eee', +}; + +export const layout = storyFn =>
{storyFn()}
; diff --git a/packages/graphiql/src/new-components/Layout.stories.js b/packages/graphiql/src/new-components/Layout.stories.js index f625b754b87..9858a8d0d4e 100644 --- a/packages/graphiql/src/new-components/Layout.stories.js +++ b/packages/graphiql/src/new-components/Layout.stories.js @@ -1,6 +1,6 @@ import React from 'react'; import Nav from './Nav'; -import List, { ListRow } from './List'; +import List, { ListRow } from './List/List'; import { useThemeLayout } from './themes/provider'; const explorer = { diff --git a/packages/graphiql/src/new-components/List.js b/packages/graphiql/src/new-components/List/List.js similarity index 78% rename from packages/graphiql/src/new-components/List.js rename to packages/graphiql/src/new-components/List/List.js index 1b87c13612a..aa6e8b3b8d4 100644 --- a/packages/graphiql/src/new-components/List.js +++ b/packages/graphiql/src/new-components/List/List.js @@ -1,14 +1,14 @@ /** @jsx jsx */ import { jsx } from 'theme-ui'; - import PropTypes from 'prop-types'; -const ListRow = ({ children, flex = false, padding = true }) => ( +const ListRow = ({ children, flex = false, padding = false }) => (
spaces.rowPadding : undefined, + minHeight: ({ spaces }) => spaces.rowMinHeight, }}> {children}
diff --git a/packages/graphiql/src/new-components/List.stories.js b/packages/graphiql/src/new-components/List/List.stories.js similarity index 57% rename from packages/graphiql/src/new-components/List.stories.js rename to packages/graphiql/src/new-components/List/List.stories.js index 95058e3bf14..3117681e405 100644 --- a/packages/graphiql/src/new-components/List.stories.js +++ b/packages/graphiql/src/new-components/List/List.stories.js @@ -11,12 +11,14 @@ const longText = Array(300) export const withFlexChild = () => (
- - { - 'Lists are a vertical stack of components and form the basis of most modules. This one is very long' - } + +
+ { + 'Lists are a vertical stack of components and form the basis of most modules. This one is very long' + } +
- + {'You normally want 1 flex area that grows forever like this one'} {longText} {'the end'} @@ -28,17 +30,17 @@ export const withFlexChild = () => ( export const withStackedRows = () => (
- {'Title'} - {'Navigation'} - {'Search'} - {'Filter'} - + {'Title'} + {'Navigation'} + {'Search'} + {'Filter'} + {'Actual content'} {longText} {'Actual content ends here'} - {'Footer'} - {'Footers footer'} + {'Footer'} + {'Footers footer'}
); diff --git a/packages/graphiql/src/new-components/Tabs.js b/packages/graphiql/src/new-components/Tabs.js deleted file mode 100644 index 815301ca152..00000000000 --- a/packages/graphiql/src/new-components/Tabs.js +++ /dev/null @@ -1,77 +0,0 @@ -/** @jsx jsx */ -import { jsx } from 'theme-ui'; -import PropTypes from 'prop-types'; - -const Tab = ({ active, ...props }) => ( - - -
  • - -
  • -
  • - -
  • - -
    -
    - -
    -
    + Three + + + +
    +
    +
    +
      +
    • + +
    • +
    • +
      + +
    • +
    +
    +
    `; -exports[`Storyshots Type Type 1`] = ` +exports[`Storyshots Toolbar Basic 1`] = `
    -

    - Title -

    +

    + Toolbars group together widgets in a flexbox. You can cutomize what type of + justification to use and if elements go together it'll add dividers + between them +

    +
    +
    +
    +
      +
    • +
      + Some text +
      +
    • +
    • +
      +
      + Some text +
      +
    • +
    • +
      +
      + Some text +
      +
    • +
    +
    +
    +
    +
    +
      +
    • +
      + Some text +
      +
    • +
    • +
      +
      + Some text +
      +
    • +
    • +
      +
      + Some text +
      +
    • +
    +
    +
    +
    +
    +
      +
    • +
      + Some text +
      +
    • +
    • +
      +
      + Some text +
      +
    • +
    • +
      +
      + Some text +
      +
    • +
    +
    +
    +
    +
    +
    + Some text +
    +
    + Some text +
    +
    + Some text +
    +
    +
    + +`; + +exports[`Storyshots Toolbar Toolbar With Tabs 1`] = ` +
    - +

    + The dividers don't nest so if you have tabs inside a toolbar the tabs won't get dividers +

    +
    +
    +
    +
      +
    • +
        +
      • + +
      • +
      • +
        + +
      • +
      • +
        + +
      • +
      +
    • +
    • +
      +
        +
      • + +
      • +
      • +
        + +
      • +
      • +
        + +
      • +
      +
    • +
    +
    +
    +
    - Small explainer text - +
    +
      +
    • +
        +
      • + +
      • +
      • +
        + +
      • +
      • +
        + +
      • +
      +
    • +
    • +
      +
        +
      • + +
      • +
      • +
        + +
      • +
      • +
        + +
      • +
      +
    • +
    +
    +
    +
    +
    +
      +
    • +
        +
      • + +
      • +
      • +
        + +
      • +
      • +
        + +
      • +
      +
    • +
    • +
      +
        +
      • + +
      • +
      • +
        + +
      • +
      • +
        + +
      • +
      +
    • +
    +
    +
    +
    +
    +
      +
    • + +
    • +
    • +
      + +
    • +
    • +
      + +
    • +
    +
      +
    • + +
    • +
    • +
      + +
    • +
    • +
      + +
    • +
    +
    +
    + +`; + +exports[`Storyshots Type Type 1`] = ` +
    - Normal text +
    +

    + Title +

    +
    +
    + + Small explainer text + +
    +
    + Normal text +
    `; diff --git a/packages/graphiql/src/new-components/themes/default/index.js b/packages/graphiql/src/new-components/themes/default/index.js index a3294d86017..038b2f97d2d 100644 --- a/packages/graphiql/src/new-components/themes/default/index.js +++ b/packages/graphiql/src/new-components/themes/default/index.js @@ -22,16 +22,23 @@ const colors = { border: palette.neutral[90], }; +const space = [0, 5, 10, 15, 20]; +const fontSizes = [12, 16, 20]; + const theme = { fonts: { body: 'system-ui, sans-serif', heading: '"Avenir Next", sans-serif', monospace: 'Menlo, monospace', }, - fontSizes: [12, 16, 20], - space: [0, 5, 10, 15, 20], + fontSizes, + space, colors, transitions: ['.25s'], + spaces: { + rowPadding: space[3], + rowMinHeight: space[3] + fontSizes[1] + space[3], + }, shadows: { card: `0 0 0 .1px ${colors.border}, 0 1px 4px 0 ${colors.border}`, primaryUnderline: `inset 0 -4px 0 0 ${colors.primary}`,