Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(variants): add defaults to theme #51

Merged
merged 10 commits into from
Sep 22, 2020
Merged

Conversation

Johan-dutoit
Copy link
Contributor

@Johan-dutoit Johan-dutoit commented Sep 16, 2020

Goal
The idea of this PR is to add support for defaults in the theme object for the specific variant.

Problem
Currently specifying defaults can only be done when creating a variant, which is both limiting (i.e. no defaults for the createText export) and not in the same location as all the other styles (i.e. developers will forget they exist).

Usage

textVariants: {
    defaults: {
      fontFamily: 'Roboto',
      color: 'primaryText',
    },
    title: {
        fontSize: 24
        ...
    },
}

Implementation
Styles will be applied in the following order
{...createVariantDefaults, ...themeVariantDefaults, ...actualVariantStyles},

Tests
Existing tests completed successfully without modifications.
New tests added to ensure the styles are applied (and in the correct order, with overrides).

Closes GH-49

Copy link
Contributor

@JoelBesada JoelBesada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Just one note, this will allow you to pass variant="defaults" to a component. I think we should remove "defaults" as a valid option, at least in the prop types.

README.md Outdated Show resolved Hide resolved
@Johan-dutoit
Copy link
Contributor Author

Just one note, this will allow you to pass variant="defaults" to a component. I think we should remove "defaults" as a valid option, at least in the prop types.

I too noticed this, but didn't see much harm.
Let me see if I can squeeze in an Omit somewhere.

@Johan-dutoit
Copy link
Contributor Author

Added in an omit for defaults (to the types only): /~https://github.com/Shopify/restyle/pull/51/files#diff-d11836bc5f23eb547c1e6e3dd4325c12R80

Co-authored-by: Joel Besada <joel.besada@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How can I make a "base" variant that multiple variants will extend it?
2 participants