Skip to content

Commit

Permalink
Merge pull request #1451 from cozy/cozy-theme-button
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne authored May 4, 2020
2 parents 4da4464 + dd6b740 commit 9c604f7
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 17 deletions.
3 changes: 2 additions & 1 deletion docs/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ module.exports = {
'../react/AppIcon/index.jsx',
'../react/CipherIcon/index.jsx',
'../react/QuotaAlert/index.jsx',
'../react/PasswordExample/index.jsx'
'../react/PasswordExample/index.jsx',
'../react/CozyTheme/index.jsx'
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cozy-ui",
"version": "0.0.0-development",
"version": "35.14.0-beta.1",
"description": "Cozy apps UI SDK",
"main": "./index.js",
"bin": {
Expand Down
8 changes: 6 additions & 2 deletions react/BarButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ export class BarButton extends PureComponent {
const { disabled, icon, href, onClick, className } = this.props
return (
<MaybeLink
className={cx(styles['c-bar-btn'], className)}
className={cx(
styles.BarButton,
disabled && styles['BarButton--disabled'],
className
)}
href={!disabled ? href : undefined}
onClick={!disabled ? onClick : undefined}
>
<Icon icon={icon} className={disabled ? 'u-silver' : 'u-coolGrey'} />
<Icon icon={icon} className={styles.BarButtonIcon} />
</MaybeLink>
)
}
Expand Down
14 changes: 12 additions & 2 deletions react/BarButton/styles.styl
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
@require 'tools/mixins'

.c-bar-btn {
.BarButton
display flex
align-items center
justify-content center
width rem(48)
height rem(48)
}

:root
--barIconColor var(--coolGrey)
--barIconColorDisabled var(--silver)

.BarButtonIcon
color var(--barIconColor)

.BarButton--disabled
.BarButtonIcon
color var(--barIconColorDisabled)
1 change: 0 additions & 1 deletion react/Button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const BaseButton = props => {
tag: Tag,
...restProps
} = props

const transformProps = tagToTransformProps[Tag] || identity
const tooltip = iconOnly ? label : null
const iconOnlyClass = iconOnly ? 'u-visuallyhidden' : null
Expand Down
45 changes: 45 additions & 0 deletions react/CozyTheme/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
An area of a page can have a different CozyTheme and components inside
will be automatically styled.

- At the moment only some Buttons support this.


```
import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme';
import { Title, SubTitle } from 'cozy-ui/transpiled/react/Text';
import Button from 'cozy-ui/transpiled/react/Button';
import BarButton from 'cozy-ui/transpiled/react/BarButton';
const props = [{}, { disabled: true}, { busy: true }];
const themesSupportingContext = [
'regular',
'secondary'
];
<CozyTheme variant='inverted' className='u-p-1'>
<Title className='u-white'>Inverted theme</Title>
<SubTitle className='u-white'>Buttons</SubTitle>
{themesSupportingContext.map(theme =>
<p key={theme}>{
props.map(
props => <Button key={theme + JSON.stringify(props)} label={theme} theme={theme} {...props} />
)
}</p>
)}
<SubTitle className='u-white'>BarButton</SubTitle>
<BarButton icon='dots' />
</CozyTheme>
```

`MuiCozyTheme` is used under the hood so that MaterialUI components are
also styled.

```
import MuiButton from '@material-ui/core/Button';
<div className='u-bg-primaryColor u-p-1'>
<CozyTheme variant='inverted'>
<MuiButton>Default button with Cozy theme</MuiButton>
</CozyTheme>
</div>
20 changes: 20 additions & 0 deletions react/CozyTheme/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { createContext, useContext } from 'react'
import MuiCozyTheme from '../MuiCozyTheme'
import styles from './styles.styl'
import cx from 'classnames'

export const CozyThemeContext = createContext()

const CozyTheme = ({ variant, children, className }) => (
<CozyThemeContext.Provider value={variant}>
<MuiCozyTheme variant={variant}>
<div className={cx(className, styles[`CozyTheme--${variant}`])}>
{children}
</div>
</MuiCozyTheme>
</CozyThemeContext.Provider>
)

export const useCozyTheme = () => useContext(CozyThemeContext)

export default CozyTheme
17 changes: 17 additions & 0 deletions react/CozyTheme/styles.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$translucentWhite1=rgba(255, 255, 255, 0.24)
$translucentWhite2=rgba(255, 255, 255, 0.88)

.CozyTheme--inverted
background: var(--primaryColor)
--barIconColor var(--primaryContrastTextColor)
--barIconColorDisabled $translucentWhite2

--regularButtonPrimaryColor: var(--primaryContrastTextColor)
--regularButtonSecondaryColor: var(--primaryContrastTextColor)
--regularButtonActiveColor: $translucentWhite2
--regularButtonConstrastColor: var(--primaryColor)

--secondaryButtonPrimaryColor: var(--primaryColor)
--secondaryButtonSecondaryColor: var(--white)
--secondaryButtonActiveColor: $translucentWhite1
--secondaryButtonContrastColor: var(--white)
8 changes: 4 additions & 4 deletions react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,29 @@ exports[`Badge should render examples: Badge 2`] = `

exports[`BarButton should render examples: BarButton 1`] = `
"<div>
<div class=\\"styles__c-bar-btn___1Jc6J\\"><svg class=\\"u-silver styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<div class=\\"styles__BarButton___3z5Er styles__BarButton--disabled___5e3Ll\\"><svg class=\\"styles__BarButtonIcon___1pSOT styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#previous\\"></use>
</svg></div>
</div>"
`;

exports[`BarButton should render examples: BarButton 2`] = `
"<div><a href=\\"http://cozy.io\\" class=\\"styles__c-bar-btn___1Jc6J\\"><svg class=\\"u-coolGrey styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
"<div><a href=\\"http://cozy.io\\" class=\\"styles__BarButton___3z5Er\\"><svg class=\\"styles__BarButtonIcon___1pSOT styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#upload\\"></use>
</svg></a></div>"
`;

exports[`BarButton should render examples: BarButton 3`] = `
"<div>
<div class=\\"styles__c-bar-btn___1Jc6J\\"><svg class=\\"u-coolGrey styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<div class=\\"styles__BarButton___3z5Er\\"><svg class=\\"styles__BarButtonIcon___1pSOT styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#cube\\"></use>
</svg></div>
</div>"
`;

exports[`BarButton should render examples: BarButton 4`] = `
"<div>
<div class=\\"styles__c-bar-btn___1Jc6J\\"><svg class=\\"u-coolGrey styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<div class=\\"styles__BarButton___3z5Er\\"><svg class=\\"styles__BarButtonIcon___1pSOT styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#gear\\"></use>
</svg></div>
</div>"
Expand Down
1 change: 1 addition & 0 deletions react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ export {
export { default as BarContextProvider } from './BarContextProvider'
export { default as BarTitle } from './BarTitle'
export { default as UploadQueue } from './UploadQueue'
export { default as CozyTheme } from './CozyTheme'
35 changes: 29 additions & 6 deletions stylus/components/button.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
@require '../utilities/text'
@require '../tools/mixins'

:root
--regularButtonPrimaryColor: var(--primaryColor)
--regularButtonSecondaryColor: var(--primaryColor)
--regularButtonActiveColor: var(--primaryColorDark)
--regularButtonConstrastColor: var(--primaryContrastTextColor)

--secondaryButtonPrimaryColor: var(--white)
--secondaryButtonSecondaryColor: var(--silver)
--secondaryButtonActiveColor: var(--silver)
--secondaryButtonContrastColor: var(--black)
/*------------------------------------*\
Variants
\*------------------------------------*/
regularTheme = {
primaryColor: var(--dodgerBlue), secondaryColor: var(--dodgerBlue), activeColor: var(--scienceBlue), contrastColor: var(--white)
primaryColor: var(--regularButtonPrimaryColor),
secondaryColor: var(--regularButtonSecondaryColor),
activeColor: var(--regularButtonActiveColor),
contrastColor: var(--regularButtonConstrastColor)
}
secondaryTheme = {
primaryColor: var(--secondaryButtonPrimaryColor),
secondaryColor: var(--secondaryButtonSecondaryColor),
activeColor: var(--secondaryButtonActiveColor),
contrastColor: var(--secondaryButtonContrastColor)
}
ghostTheme = {
primaryColor: var(--zircon), secondaryColor: var(--frenchPass), activeColor: var(--frenchPass), contrastColor: var(--dodgerBlue)
primaryColor: var(--zircon), secondaryColor: var(--frenchPass), activeColor: var(--frenchPass), contrastColor: var(--primaryColor)
}
highlightTheme = {
primaryColor: var(--emerald), secondaryColor: var(--emerald), activeColor: var(--malachite), contrastColor: var(--white)
Expand All @@ -21,14 +40,11 @@ dangerTheme = {
alphaTheme = {
primaryColor: transparent, secondaryColor: var(--white), activeColor: var(--scienceBlue), contrastColor: var(--white)
}
secondaryTheme = {
primaryColor: var(--white), secondaryColor: var(--silver), activeColor: var(--silver), contrastColor: var(--black)
}
dangerOutlineTheme = {
primaryColor: var(--white), secondaryColor: var(--yourPink), activeColor: var(--yourPink), contrastColor: var(--pomegranate)
}
text = {
primaryColor: transparent, secondaryColor: transparent, activeColor: transparent, contrastColor: var(--dodgerBlue)
primaryColor: transparent, secondaryColor: transparent, activeColor: transparent, contrastColor: var(--primaryColor)
}

// We turn stylint off since without semicolons, stylus fails to
Expand All @@ -51,6 +67,7 @@ themedBtn(theme)
&[disabled]
&[aria-disabled=true]
&:hover
border-color: theme['secondaryColor']
background-color: theme['primaryColor']

/*------------------------------------*\
Expand Down Expand Up @@ -110,6 +127,9 @@ $button
$button--regular // Deprecated
@extend $button

$button--regularInverted
themedBtn(regularInvertedTheme)

$button--ghost
themedBtn(ghostTheme)
border-style dashed
Expand All @@ -126,6 +146,9 @@ $button--danger
$button--secondary
themedBtn(secondaryTheme)

$button--secondaryInverted
themedBtn(secondaryInvertedTheme)

$button--danger-outline
themedBtn(dangerOutlineTheme)

Expand Down
2 changes: 2 additions & 0 deletions stylus/settings/palette.styl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
Primary
Stylus: primaryColor - #297EF2, CSS: var(--primaryColor)
Stylus: primaryColorDark - #0B61D6, CSS: var(--primaryColorDark)
Stylus: primaryColorLight - #5C9DF5, CSS: var(--primaryColorLight)
Stylus: primaryColorLighter - #4B93F7, CSS: var(--primaryColorLighter)
Stylus: primaryColorLightest - #9FC4FB, CSS: var(--primaryColorLightest)
Expand All @@ -151,6 +152,7 @@
Styleguide Settings.theme.primary
*/
--primaryColor var(--dodgerBlue)
--primaryColorDark var(--scienceBlue)
--primaryColorLight #5C9DF5 // lighten(dodgerBlue, 24)
--primaryColorLighter #4B93F7
--primaryColorLightest #9FC4FB
Expand Down

0 comments on commit 9c604f7

Please sign in to comment.