Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

[V2] common button component + stories #1624

Closed
wants to merge 9 commits into from

Conversation

W3stside
Copy link
Contributor

Start of theming with styled-components and common button component aimed at reuse

Would love feedback on data structure of theme object

@gnosis-info
Copy link

Travis automatic deployment:

src/components/common/Button/index.tsx Outdated Show resolved Hide resolved
src/styles/theme.ts Outdated Show resolved Hide resolved
src/styles/theme.ts Outdated Show resolved Hide resolved
src/styles/theme.ts Outdated Show resolved Hide resolved
src/components/common/Button/index.tsx Outdated Show resolved Hide resolved
Comment on lines +24 to +40
border-color: ${({ button }): string => button.bg1Hover};
background-color: ${({ button }): string => button.bg1Hover};
color: ${({ button }): string => button.text1Hover};
}

border-radius: 2rem;
cursor: pointer;
font-weight: bold;
outline: 0;
padding: 0.5rem 1rem;

transition: all 0.2s ease-in-out;
transition-property: color, background-color, border-color, opacity;

&.cancel {
background: transparent;
color: var(--color-text-active);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really not a fan of how we mix styled-comp theme and css vars theme, but whatever

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me neither, will rework for prop based logic 🤙

Copy link
Contributor

Choose a reason for hiding this comment

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

agree. In v2 we could use only the theme

src/storybook/decorators.tsx Outdated Show resolved Hide resolved
Comment on lines 19 to 22
const [darkMode, setDarkMode] = React.useState(false)
const theme = colors(darkMode)

const handleDarkMode = React.useCallback(() => setDarkMode((darkMode) => !darkMode), [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Wanna extract this into a hook?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sir 🤛

src/styles/theme.ts Outdated Show resolved Hide resolved
@W3stside
Copy link
Contributor Author

@Velenir thanks, will review. Thoughts on theme data structure? Feels like it could be optimised

Comment on lines +24 to +40
border-color: ${({ button }): string => button.bg1Hover};
background-color: ${({ button }): string => button.bg1Hover};
color: ${({ button }): string => button.text1Hover};
}

border-radius: 2rem;
cursor: pointer;
font-weight: bold;
outline: 0;
padding: 0.5rem 1rem;

transition: all 0.2s ease-in-out;
transition-property: color, background-color, border-color, opacity;

&.cancel {
background: transparent;
color: var(--color-text-active);
Copy link
Contributor

Choose a reason for hiding this comment

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

agree. In v2 we could use only the theme

src/styles/theme.ts Show resolved Hide resolved
// $alt button theme toggle
$alt?: boolean
$border?: boolean
theme: ThemedStyledProps<ColourTheme, ColourTheme>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we injecting explicitly the Theme instead of using Uniswap approach of

declare module 'styled-components' {
  export interface DefaultTheme extends Colors {
  }
}

This way, all components have access to the theme and we don't need to add it on every prop decoration. They are part of their context.

https://styled-components.com/docs/advanced

export default {
title: 'Common/Button',
component: ButtonBase,
decorators: [DarkModeThemeToggler],
Copy link
Contributor

Choose a reason for hiding this comment

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

Very very cool! 🤟

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call it just ThemeToggler?

return (
<>
<ThemeProvider theme={theme}>
<Frame style={{ backgroundColor: 'lightgray' }}>{DecoratedStory()}</Frame>
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't add this gray frame.
I think, we can add a second decorator for the frame and leave the default color.

const handleDarkMode = (): void => setDarkMode((darkMode) => !darkMode)

return (
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the background of the whole story should be the background of the app

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea. i'll make these changes in whichever PR is preferred #1624 or #1626

return theme
}

// FOR REFERENCE
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, but this is from v1?

not sure if we will need it even as a reference. We have the colors in the original design.
what do you think @biocom

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we want to consolidate theming between Simple Swap <-> Trading Interface. But I'd say in terms of colors they likely 90% overlap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool @biocom this is what i needed. will transition my latest pr #1626

@W3stside W3stside mentioned this pull request Nov 17, 2020
3 tasks
@W3stside
Copy link
Contributor Author

closing in favour for the BIGGER, the BETTER, the SEXIER, #1626 and co.

@W3stside W3stside closed this Nov 20, 2020
@anxolin anxolin mentioned this pull request Jan 12, 2021
16 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants