square / maker

Maker Design System by Square
https://square.github.io/maker/styleguide/latest-stable/
Other
63 stars 14 forks source link

feat!: user-defined theme variants for mtext & mbutton #278

Closed pretzelhammer closed 2 years ago

pretzelhammer commented 2 years ago

Describe the problem this PR addresses

Describe the changes in this PR

Bulk of the work in done in these key files:

Theming MText (& MHeading) before this PR:

text: {
    // default theme for texts
    fontFamily: 'inherit',
    size: 0,
    color: '@colors.text',
    fontWeight: 400,
},
heading: {
    // default theme for headings
    fontFamily: 'inherit',
    size: 2,
    color: '@colors.heading',
    fontWeight: 700,
},

Theming MText after this PR:

text: {
    // default theme for all texts
    size: 0,
    fontFamily: 'inherit',
    color: '@colors.text',
    element: 'p',
    fontWeight: 'inherit',
    fontStyle: 'inherit',
    textTransform: 'inherit',
    textAlign: 'inherit',
    // default variant for all texts is body
    variant: 'body',
    variants: {
        headline: {
            // default theme for headline texts
            size: 4,
            fontWeight: '700',
            element: 'h1',
            color: '@colors.heading',
        },
        title: {
            // default theme for title texts
            size: 2,
            fontWeight: '700',
            element: 'h2',
            color: '@colors.heading',
        },
        body: {
            // default theme for body texts
            size: 0,
            fontWeight: '400',
            element: 'p',
        },
        label: {
            // default theme for label texts
            size: -1,
            fontWeight: '700',
            element: 'h6',
            textTransform: 'uppercase',
        },
    },
},

Making Headlines, Titles, Body text, and Label text before this PR:

<template>
    <m-heading :size="4">headline</m-heading>
    <m-heading>title</m-heading>
    <m-text>body</m-text>
    <m-heading element="h6" :size="-1">label</m-heading>
</template>

Making Headlines, Titles, Body text, and Label text after this PR:

<template>
    <m-text variant="headline">headline</m-text>
    <m-text variant="title">title</m-text>
    <m-text>body</m-text>
    <m-text variant="label">label</m-text>
</template>

Migration Guide

github-actions[bot] commented 2 years ago

Styleguide deployed to https://square.github.io/maker/styleguide/text-variants/#/

github-actions[bot] commented 2 years ago

📊 Package size report   -2.65%↓

File Before After
components/Button/script.js 6.2 kB -0.96%↓6.2 kB
components/Heading/index.js 46 B
components/Heading/script.js 4.7 kB
components/Heading/styles.css 5.1 kB
components/Text/script.js 4.5 kB 3%↑4.6 kB
components/Text/styles.css 5.1 kB -6.96%↓4.7 kB
components/Theme/script.js 5.5 kB 19%↑6.5 kB
utils/css-validator.js 933 B
Total (Includes all files) 1.3 MB -2.65%↓1.2 MB
Tarball size 235.6 kB -2.36%↓230.1 kB
Unchanged files | File | Size | | --------------------------------------------------------------------------------- | --------: | | `components/ActionBar/index.js` | `46 B` | | `components/ActionBar/script.js` | `14.5 kB` | | `components/ActionBar/styles.css` | `5.5 kB` | | `components/Blade/index.js` | `46 B` | | `components/Blade/script.js` | `6.2 kB` | | `components/Blade/styles.css` | `740 B` | | `components/Button/index.js` | `46 B` | | `components/Button/styles.css` | `3.6 kB` | | `components/Calendar/index.js` | `46 B` | | `components/Calendar/script.js` | `7.7 kB` | | `components/Calendar/styles.css` | `2.0 kB` | | `components/Card/index.js` | `46 B` | | `components/Card/script.js` | `1.7 kB` | | `components/Card/styles.css` | `196 B` | | `components/Checkbox/index.js` | `46 B` | | `components/Checkbox/script.js` | `3.9 kB` | | `components/Checkbox/styles.css` | `1.3 kB` | | `components/Choice/index.js` | `46 B` | | `components/Choice/script.js` | `4.5 kB` | | `components/Choice/styles.css` | `1.2 kB` | | `components/Container/index.js` | `46 B` | | `components/Container/script.js` | `4.5 kB` | | `components/Container/styles.css` | `1.0 kB` | | `components/Dialog/index.js` | `46 B` | | `components/Dialog/script.js` | `7.4 kB` | | `components/Dialog/styles.css` | `1.2 kB` | | `components/Divider/index.js` | `46 B` | | `components/Divider/script.js` | `1.7 kB` | | `components/Divider/styles.css` | `160 B` | | `components/Image/index.js` | `46 B` | | `components/Image/script.js` | `3.3 kB` | | `components/Image/styles.css` | `208 B` | | `components/ImageUploader/index.js` | `46 B` | | `components/ImageUploader/script.js` | `11.7 kB` | | `components/ImageUploader/styles.css` | `2.3 kB` | | `components/Input/index.js` | `46 B` | | `components/Input/script.js` | `4.2 kB` | | `components/Input/styles.css` | `2.1 kB` | | `components/Loading/index.js` | `46 B` | | `components/Loading/script.js` | `2.2 kB` | | `components/Loading/styles.css` | `1.2 kB` | | `components/Modal/index.js` | `46 B` | | `components/Modal/script.js` | `9.8 kB` | | `components/Modal/styles.css` | `1.0 kB` | | `components/Notice/index.js` | `46 B` | | `components/Notice/script.js` | `4.7 kB` | | `components/Notice/styles.css` | `983 B` | | `components/PinInput/index.js` | `46 B` | | `components/PinInput/script.js` | `4.5 kB` | | `components/PinInput/styles.css` | `1.2 kB` | | `components/Popover/index.js` | `46 B` | | `components/Popover/script.js` | `9.9 kB` | | `components/Popover/styles.css` | `446 B` | | `components/ProgressBar/index.js` | `46 B` | | `components/ProgressBar/script.js` | `2.9 kB` | | `components/ProgressBar/styles.css` | `1.1 kB` | | `components/Radio/index.js` | `46 B` | | `components/Radio/script.js` | `3.6 kB` | | `components/Radio/styles.css` | `1.4 kB` | | `components/SegmentedControl/index.js` | `46 B` | | `components/SegmentedControl/script.js` | `3.1 kB` | | `components/SegmentedControl/styles.css` | `870 B` | | `components/Select/index.js` | `46 B` | | `components/Select/script.js` | `5.0 kB` | | `components/Select/styles.css` | `1.9 kB` | | `components/Skeleton/index.js` | `46 B` | | `components/Skeleton/script.js` | `4.3 kB` | | `components/Skeleton/styles.css` | `889 B` | | `components/StarRating/index.js` | `46 B` | | `components/StarRating/script.js` | `5.9 kB` | | `components/StarRating/styles.css` | `322 B` | | `components/Stepper/index.js` | `46 B` | | `components/Stepper/script.js` | `4.2 kB` | | `components/Stepper/styles.css` | `402 B` | | `components/Text/index.js` | `46 B` | | `components/Textarea/index.js` | `46 B` | | `components/Textarea/script.js` | `3.6 kB` | | `components/Textarea/styles.css` | `1.4 kB` | | `components/TextButton/index.js` | `46 B` | | `components/TextButton/script.js` | `3.7 kB` | | `components/TextButton/styles.css` | `1.4 kB` | | `components/Theme/index.js` | `46 B` | | `components/Theme/styles.css` | `136 B` | | `components/Toggle/index.js` | `46 B` | | `components/Toggle/script.js` | `3.7 kB` | | `components/Toggle/styles.css` | `3.5 kB` | | `components/TouchCapture/index.js` | `25 B` | | `components/TouchCapture/script.js` | `3.5 kB` | | `components/TransitionFadeIn/index.js` | `25 B` | | `components/TransitionFadeIn/script.js` | `2.3 kB` | | `components/TransitionResize/index.js` | `25 B` | | `components/TransitionResize/script.js` | `3.6 kB` | | `components/TransitionSpringLeft/index.js` | `25 B` | | `components/TransitionSpringLeft/script.js` | `2.3 kB` | | `components/TransitionSpringUp/index.js` | `25 B` | | `components/TransitionSpringUp/script.js` | `2.3 kB` | | `components/TransitionStaggered/index.js` | `25 B` | | `components/TransitionStaggered/script.js` | `2.5 kB` | | [`LICENSE`](https://github.com/square/maker/blob/text-variants/LICENSE) | `552 B` | | [`package.json`](https://github.com/square/maker/blob/text-variants/package.json) | `5.0 kB` | | [`README.md`](https://github.com/square/maker/blob/text-variants/README.md) | `327 B` | | `utils/assert.js` | `1.1 kB` | | `utils/BlockFormControlLayout/index.js` | `46 B` | | `utils/BlockFormControlLayout/script.js` | `1.8 kB` | | `utils/BlockFormControlLayout/styles.css` | `234 B` | | `utils/debug.js` | `1.0 kB` | | `utils/get-contrast.js` | `1.1 kB` | | `utils/InlineFormControlLayout/index.js` | `46 B` | | `utils/InlineFormControlLayout/script.js` | `2.5 kB` | | `utils/InlineFormControlLayout/styles.css` | `380 B` | | `utils/Transition/index.js` | `25 B` | | `utils/Transition/script.js` | `2.4 kB` | | `utils/TransitionResponsive/index.js` | `25 B` | | `utils/TransitionResponsive/script.js` | `2.2 kB` | | `utils/transitions.js` | `4.2 kB` |
Hidden files | File | Before | After | | ----------------------------------------------- | --------: | --------------------------: | | `components/ActionBar/script.js.map` | `55.4 kB` | `55.4 kB` | | `components/ActionBar/styles.css.map` | `18.3 kB` | `18.3 kB` | | `components/Blade/script.js.map` | `23.3 kB` | `23.3 kB` | | `components/Blade/styles.css.map` | `3.9 kB` | `3.9 kB` | | `components/Button/script.js.map` | `24.7 kB` | -0.12%↓`24.7 kB` | | `components/Button/styles.css.map` | `10.6 kB` | -0.24%↓`10.6 kB` | | `components/Calendar/script.js.map` | `29.5 kB` | `29.5 kB` | | `components/Calendar/styles.css.map` | `10.3 kB` | `10.3 kB` | | `components/Card/script.js.map` | `8.8 kB` | `8.8 kB` | | `components/Card/styles.css.map` | `711 B` | `711 B` | | `components/Checkbox/script.js.map` | `18.6 kB` | `18.6 kB` | | `components/Checkbox/styles.css.map` | `3.6 kB` | `3.6 kB` | | `components/Choice/script.js.map` | `19.7 kB` | `19.7 kB` | | `components/Choice/styles.css.map` | `5.9 kB` | `5.9 kB` | | `components/Container/script.js.map` | `18.1 kB` | `18.1 kB` | | `components/Container/styles.css.map` | `4.9 kB` | `4.9 kB` | | `components/Dialog/script.js.map` | `28.6 kB` | `28.6 kB` | | `components/Dialog/styles.css.map` | `6.8 kB` | `6.8 kB` | | `components/Divider/script.js.map` | `8.8 kB` | `8.8 kB` | | `components/Divider/styles.css.map` | `723 B` | `723 B` | | `components/Heading/script.js.map` | `22.4 kB` | — | | `components/Heading/styles.css.map` | `11.6 kB` | — | | `components/Image/script.js.map` | `14.1 kB` | `14.1 kB` | | `components/Image/styles.css.map` | `2.9 kB` | `2.9 kB` | | `components/ImageUploader/script.js.map` | `45.9 kB` | `45.9 kB` | | `components/ImageUploader/styles.css.map` | `20.2 kB` | `20.2 kB` | | `components/Input/script.js.map` | `20.1 kB` | `20.1 kB` | | `components/Input/styles.css.map` | `4.9 kB` | `4.9 kB` | | `components/Loading/script.js.map` | `11.0 kB` | `11.0 kB` | | `components/Loading/styles.css.map` | `2.3 kB` | `2.3 kB` | | `components/Modal/script.js.map` | `34.9 kB` | `34.9 kB` | | `components/Modal/styles.css.map` | `10.7 kB` | `10.7 kB` | | `components/Notice/script.js.map` | `18.6 kB` | `18.6 kB` | | `components/Notice/styles.css.map` | `4.2 kB` | `4.2 kB` | | `components/PinInput/script.js.map` | `18.4 kB` | `18.4 kB` | | `components/PinInput/styles.css.map` | `7.0 kB` | `7.0 kB` | | `components/Popover/script.js.map` | `35.1 kB` | `35.1 kB` | | `components/Popover/styles.css.map` | `5.7 kB` | `5.7 kB` | | `components/ProgressBar/script.js.map` | `13.3 kB` | `13.3 kB` | | `components/ProgressBar/styles.css.map` | `2.6 kB` | `2.6 kB` | | `components/Radio/script.js.map` | `17.5 kB` | `17.5 kB` | | `components/Radio/styles.css.map` | `3.5 kB` | `3.5 kB` | | `components/SegmentedControl/script.js.map` | `14.1 kB` | `14.1 kB` | | `components/SegmentedControl/styles.css.map` | `3.3 kB` | `3.3 kB` | | `components/Select/script.js.map` | `23.0 kB` | `23.0 kB` | | `components/Select/styles.css.map` | `5.7 kB` | `5.7 kB` | | `components/Skeleton/script.js.map` | `17.7 kB` | `17.7 kB` | | `components/Skeleton/styles.css.map` | `3.0 kB` | `3.0 kB` | | `components/StarRating/script.js.map` | `22.3 kB` | `22.3 kB` | | `components/StarRating/styles.css.map` | `6.3 kB` | `6.3 kB` | | `components/Stepper/script.js.map` | `17.3 kB` | `17.3 kB` | | `components/Stepper/styles.css.map` | `3.8 kB` | `3.8 kB` | | `components/Text/script.js.map` | `21.5 kB` | 4%↑`22.3 kB` | | `components/Text/styles.css.map` | `10.9 kB` | 5%↑`11.5 kB` | | `components/Textarea/script.js.map` | `17.6 kB` | `17.6 kB` | | `components/Textarea/styles.css.map` | `3.8 kB` | `3.8 kB` | | `components/TextButton/script.js.map` | `16.8 kB` | `16.8 kB` | | `components/TextButton/styles.css.map` | `4.2 kB` | `4.2 kB` | | `components/Theme/script.js.map` | `21.4 kB` | 18%↑`25.3 kB` | | `components/Theme/styles.css.map` | `2.2 kB` | `2.2 kB` | | `components/Toggle/script.js.map` | `19.6 kB` | `19.6 kB` | | `components/Toggle/styles.css.map` | `5.4 kB` | `5.4 kB` | | `components/TouchCapture/script.js.map` | `12.0 kB` | `12.0 kB` | | `components/TransitionFadeIn/script.js.map` | `10.5 kB` | `10.5 kB` | | `components/TransitionResize/script.js.map` | `14.4 kB` | `14.4 kB` | | `components/TransitionSpringLeft/script.js.map` | `10.5 kB` | `10.5 kB` | | `components/TransitionSpringUp/script.js.map` | `10.5 kB` | `10.5 kB` | | `components/TransitionStaggered/script.js.map` | `11.1 kB` | `11.1 kB` | | `utils/assert.js.map` | `4.2 kB` | `4.2 kB` | | `utils/BlockFormControlLayout/script.js.map` | `8.4 kB` | `8.4 kB` | | `utils/BlockFormControlLayout/styles.css.map` | `762 B` | `762 B` | | `utils/css-validator.js.map` | — | `3.3 kB` | | `utils/debug.js.map` | `3.6 kB` | `3.6 kB` | | `utils/get-contrast.js.map` | `4.9 kB` | `4.9 kB` | | `utils/InlineFormControlLayout/script.js.map` | `12.8 kB` | `12.8 kB` | | `utils/InlineFormControlLayout/styles.css.map` | `1.5 kB` | `1.5 kB` | | `utils/Transition/script.js.map` | `10.7 kB` | `10.7 kB` | | `utils/TransitionResponsive/script.js.map` | `10.3 kB` | `10.3 kB` | | `utils/transitions.js.map` | `16.8 kB` | `16.8 kB` |

🤖 This report was automatically generated by pkg-size-action

github-actions[bot] commented 2 years ago

Styleguide deployed to https://square.github.io/maker/styleguide/text-variants/#/

landondurnan commented 2 years ago

Before merging this breaking change we should understand that there's existing gaps with our theme output when it comes to our default font-family and weights. Every other component we have that will leverage the font family, weights, and sizes will also need to be updated. Buttons, forms, etc all should reflect the default output as well and it doesn't seem likely that we will want to (or in some cases even can) embed a text component into every other component that needs to have the same styling.

While this PR resolves the larger issue we have with regular heading and text elements -- we need to think more holistically here. If a breaking change is inevitable we need to at the very least do it as one major release since each one of these will increasingly create more disruptions as we work on other non-breaking changes.

You can see a simple example of this issue in our Theme demo: https://square.github.io/maker/styleguide/latest/#/Theme

CleanShot 2022-03-31 at 09 26 00

landondurnan commented 2 years ago

Discussed a bit more synchronously and the primary concern I have with this PR is the breaking change (and our frequency of them recently). I think a fair compromise at this point is to attempt to amend this code so it's non-breaking. Leaving the Heading component as-is and providing a bit more time for us to leverage this solution in practice.

The variant approach is useful and will be a helpful pattern in other components.

One other questions -- why is it necessary to set inherit as the default on so many properties? Shouldn't the default browser behavior already do this?

bashunaimiroy commented 2 years ago

I took another look and overall this would be super helpful, especially the behaviour where passing inherit for a style-related prop (e.g. color="inherit") will prevent it from getting added to inline styles. This addresses my concern here (slack link), although mostly I see why we'd prefer the "friction" factor of using the color prop explicitly and I'll be favouring that.

So that specific improvement in this PR would make my Text to MText Conversion work easier (internal github link), and the text variant improvements in general would make everything better and clarify how we add text to the Website. I don't have an opinion on the breaking change of removing MHeading, but it won't prevent my work. I endorse this. I added a minor code question, otherwise I'm ready to approve this PR.

landondurnan commented 2 years ago

Looks like there is an issue with the markdown table generation:

CleanShot 2022-03-31 at 14 19 32

The component also looks to have default element and sizes, but those don't show up in the markdown table as defaults.

github-actions[bot] commented 2 years ago

Styleguide deployed to https://square.github.io/maker/styleguide/text-variants/#/

github-actions[bot] commented 2 years ago

Styleguide deployed to https://square.github.io/maker/styleguide/text-variants/#/

github-actions[bot] commented 2 years ago

Styleguide deployed to https://square.github.io/maker/styleguide/text-variants/#/

pretzelhammer commented 2 years ago

@landondurnan

Since we don't have a way right now to release non-breaking bug fixes to multiple major releases with our semantic release jobs.

I think we might have a way to do this. Semantic release has documentation on how to do this. I'll experiment backporting a v9 bugfix to v8.

  1. Release this as a beta until we get closer to a point we know it won't be disruptive with other ongoing work.

Okay sure, I changed the base of this PR from master to beta.

landondurnan commented 2 years ago

I have concerns that we keep changing the way we're passing theme data. Variants will be useful, but we should support a global definition with the fonts.

Our current data looks something like this:

"heading": {
    "fontFamily": "Karla",
    "fontWeight": "600"
  },
  "text": {
    "fontFamily": "Domine",
    "fontWeight": "400"
  },
  "fonts": {
    "baseSize": "18",
    "sizeScale": "1.327"
  }

But in this PR its changing again after we just defined this spec in the v9 release that just came out a little over a week ago.

I think this approach by defining the component + variant as the way to style specific components is powerful for advanced used cases, but limiting in that it only styles those components.

We have numerous components that would benefit from a more generic global definition. Most of our components should inherit what's currently defined as the text.fontFamily + text.fontWeight. Then we also want the fonts.baseSize on many components or the ability to leverage one of the generated step sizes that are being generated in the Text component.

So my concern that I originally brought up about how we're changing the data structure for theming is still relevant because the way things are going is going to require every component to have props to change simple defaults for the font family, weight, and size.

What I have been recommending prior to our v9 release and again before we're looking at introducing yet another breaking change to the theme data structure is a definition based on this approach: https://theme-ui.com/theme-spec/

By leveraging this spec we can have simple global definitions (which would be sufficient for our current use cases) and support the variants for advanced use cases later.

fonts: {
    body: 'system-ui, sans-serif',
    title: 'system-ui, sans-serif',
    headline: 'system-ui, sans-serif',
    label: 'system-ui, sans-serif'
    baseSize: 16,
    sizeScale: 1.15
},
fontWeights: {
    body: 400,
    title: 700,
    headline: 400,
    label: 400,
    bold: 700
},

Using this data could be additive and non-breaking. We can still do the variant approach as a way to do additional customizations in unique scenarios, but it would alleviate the need to define every prop on every components to pass a few CSS styles.

github-actions[bot] commented 2 years ago

:tada: This PR is included in version 10.0.0-beta.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: