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

Add theme manager to provide and consume styles #347

Merged
merged 22 commits into from
Feb 7, 2022
Merged

Conversation

Saul-Mirone
Copy link
Member

@Saul-Mirone Saul-Mirone commented Feb 5, 2022

Theme Manager

Add a theme manager to provide and consume styles.

Usage

With Class Nodes

export const ThemeKey = createThemeProviderKey<{ level: number }>("heading")
export type ThemeKeyType = typeof ThemeKey;
export const heading = createNode<Keys>((utils) => {
    utils.themeManager.inject(ThemeKey);
    return {
        id,
        schema: () => ({
            content: 'inline*',
            toDOM: (node) => [`h{node.attrs.level}`, { class: utils.themeManager.get(ThemeKey, { level: 1 }) }]
            // ...
        }),
    };
});

With Theme

export const theme = themeFactory((emotion, manager) => ({
  // ...
  manager.setCustom<ThemeKeyType>('heading', ({ level }) =>
        return emotion.css`...`
  })
}))

@Saul-Mirone Saul-Mirone marked this pull request as ready for review February 7, 2022 16:11
@Saul-Mirone Saul-Mirone merged commit 307c0c7 into main Feb 7, 2022
@Saul-Mirone Saul-Mirone deleted the reorg-styles branch February 7, 2022 16:18
@tantaman
Copy link
Contributor

tantaman commented Feb 7, 2022

Thanks for doing this!

@Saul-Mirone Saul-Mirone mentioned this pull request Mar 28, 2022
21 tasks
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.

2 participants