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

Refactor svgFill utility to accept theme functions and CSS colors #594

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Prefix the change with one of these keywords:

## Unreleased

- Changed: **BREAKING** removed the `compact` prop/variant in `Alert`
- Changed: updated the styling of `Alert` conform to design system
- Changed: **BREAKING** removed the `compact` prop/variant in `Alert`
- Changed: **BREAKING** `svgFill` now only accepts CSS color literal or a `ThemeFn` which returns a CSS color (see: https://github.com/Amsterdam/amsterdam-styled-components/pull/594).

## [0.20.0]

Expand Down
2 changes: 1 addition & 1 deletion examples/create-react-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const StyledLinkListItem = styled(ListItem)`
}

${styles.IconStyle} {
${svgFill('primary')};
${svgFill(themeColor('primary', 'main'))};
}
`

Expand Down
4 changes: 2 additions & 2 deletions packages/asc-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ const StyledListItem - styled(ListItem)`
color: ${themeColor('primary')};

${styles.IconStyle} {
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
}

${styles.LinkStyle} {

&:hover {
${IconStyle} {
${svgFill('primary')};
${svgFill(themeColor('primary', 'main'))};
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/asc-ui/src/components/Alert/AlertStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default styled.div<Props>`
})};
${(level === 'attention' || level === 'error') &&
css`
${svgFill('tint', 'level1')({ theme })}
${svgFill(themeColor('tint', 'level1'))}
&, & * {
color: ${themeColor('tint', 'level1')};
}
Expand Down
18 changes: 9 additions & 9 deletions packages/asc-ui/src/components/Button/ButtonStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const getVariant = () => ({
return css`
background-color: ${themeColor('primary')};
color: ${readableColor(themeColor('primary')({ theme }))};
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};

&:hover {
background-color: ${darken(0.1, themeColor('primary')({ theme }))};
Expand All @@ -80,7 +80,7 @@ const getVariant = () => ({
return css`
background-color: ${themeColor('secondary')};
color: ${themeColor('tint', 'level1')};
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};

&:hover {
background-color: ${darken(0.1, themeColor('secondary')({ theme }))};
Expand All @@ -101,7 +101,7 @@ const getVariant = () => ({
case 'tertiary':
return css`
background-color: ${themeColor('tint', 'level4')};
${svgFill('tint', 'level7')};
${svgFill(themeColor('tint', 'level7'))};

&:hover {
background-color: ${darken(
Expand All @@ -115,7 +115,7 @@ const getVariant = () => ({
return css`
color: ${themeColor('primary')};
border: 1px solid ${themeColor('primary')};
${svgFill('primary')};
${svgFill(themeColor('primary', 'main'))};

&:hover {
outline: 1px solid ${themeColor('primary')};
Expand All @@ -131,14 +131,14 @@ const getVariant = () => ({
text-align: left;
color: ${themeColor('primary')};
background-color: rgba(0, 0, 0, 0);
${svgFill('primary')};
${svgFill(themeColor('primary', 'main'))};

/* remove transition because it's async with Icon */
${transitions('color', '0s')}

&:hover {
color: ${themeColor('secondary')};
${svgFill('secondary')};
${svgFill(themeColor('secondary', 'main'))};
}

${IconLeft} {
Expand All @@ -152,7 +152,7 @@ const getVariant = () => ({
case 'blank':
return css`
background-color: ${themeColor('tint', 'level1')};
${svgFill('tint', 'level7')}
${svgFill(themeColor('tint', 'level7'))};
&:hover {
background-color: ${themeColor('tint', 'level3')};
}
Expand All @@ -163,7 +163,7 @@ const getVariant = () => ({
background-color: ${themeColor('tint', 'level1')};
height: 32px;
padding: ${themeSpacing(1, 2)};
${svgFill('tint', 'level7')}
${svgFill(themeColor('tint', 'level7'))};
&:hover {
background-color: ${themeColor('tint', 'level4')};
}
Expand Down Expand Up @@ -264,7 +264,7 @@ const ButtonStyle = styled.button<Props>`
border: none;
color: ${themeColor('tint', 'level4')};
background-color: ${themeColor('tint', 'level3')};
${svgFill('tint', 'level4')};
${svgFill(themeColor('tint', 'level4'))};
text-decoration: none;
${({ taskflow }) =>
taskflow &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ShareButtonStyle = styled(ButtonStyle)<Props>`
}

${IconStyle} {
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
}
`

Expand Down
4 changes: 2 additions & 2 deletions packages/asc-ui/src/components/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Checkbox', () => {
cleanup()
;({ container, rerender } = render(
<ThemeProvider>
<Checkbox onChange={onChangeMock} />
<Checkbox variant="primary" onChange={onChangeMock} />
</ThemeProvider>,
))
})
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('Checkbox', () => {
// Toggle on by changing props
rerender(
<ThemeProvider>
<Checkbox checked />
<Checkbox checked variant="secondary" />
</ThemeProvider>,
)

Expand Down
12 changes: 6 additions & 6 deletions packages/asc-ui/src/components/Checkbox/CheckboxStyle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled, { css } from 'styled-components'
import { themeColor, focusStyleOutline, svgFill } from '../../utils'
import { IconStyle } from '../Icon'
import { focusStyleOutline, svgFill, themeColor } from '../../utils'
import { outlineStyle } from '../../utils/themeUtils'
import { IconStyle } from '../Icon'

type CheckboxVariant = 'primary' | 'secondary' | 'tertiary'

Expand All @@ -19,28 +19,28 @@ const getVariant = () => ({ variant }: Props) => {
return css`
color: ${themeColor('primary', 'main')};
background-color: ${themeColor('primary', 'main')};
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
`

case 'secondary':
return css`
color: ${themeColor('secondary', 'main')};
background-color: ${themeColor('secondary', 'main')};
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
`

case 'tertiary':
return css`
color: ${themeColor('tint', 'level7')};
background-color: ${themeColor('tint', 'level1')};
${svgFill('tint', 'level7')};
${svgFill(themeColor('tint', 'level7'))};
`

default:
return css`
color: ${themeColor('tint', 'level7')};
background-color: ${themeColor('tint', 'level7')};
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
`
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const StyledListItem = styled(ListItem)`
}

${IconStyle} {
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
}

${LinkStyle} {
Expand All @@ -24,7 +24,7 @@ const StyledListItem = styled(ListItem)`
text-decoration: underline;

${IconStyle} {
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Icon from '../../Icon'
import { ToggleHandlerProps } from '../../Toggle'
import IconStyle from '../../Icon/IconStyle'
import FooterHeading from '../FooterHeading'
import { svgFill } from '../../../utils'
import { svgFill, themeColor } from '../../../utils'

export type Props = ToggleHandlerProps

Expand All @@ -19,7 +19,7 @@ const ToggleFooterHeader: React.FC<Props> = ({ open, onClick, title }) => {

& > ${IconStyle} {
margin-right: 8px;
${svgFill('tint', 'level1')};
${svgFill(themeColor('tint', 'level1'))};
}
`

Expand Down
7 changes: 1 addition & 6 deletions packages/asc-ui/src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from 'react'
import IconStyle, { defaultProps, Props as IconStyleProps } from './IconStyle'

export { defaultProps }

export type Props = IconStyleProps

const Icon: React.FC<Props> = ({ children, ...otherProps }) => (
<IconStyle {...otherProps}>{children}</IconStyle>
)

export default Icon
export default IconStyle
15 changes: 4 additions & 11 deletions packages/asc-ui/src/components/Icon/IconStyle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import styled, { css } from 'styled-components'
import { svgFill } from '../../utils'
import { ThemeFn } from '../../utils/themeUtils'

export type Props = {
inline?: boolean
color?: string
color?: string | ThemeFn<string>
iconUrl?: string
size?: number
padding?: number
Expand Down Expand Up @@ -41,16 +43,7 @@ const IconStyle = styled.span<Props>`
`}
}

${({ color }) => css`
& svg {
circle,
rect,
polygon,
path {
fill: ${color};
}
}
`};
${({ color }) => color && svgFill(color)};
`

export default IconStyle
24 changes: 12 additions & 12 deletions packages/asc-ui/src/components/Link/LinkStyle.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import styled, { css } from 'styled-components'
import { themeColor } from '../../utils'
import {
svgFill,
FocusStyle,
getFocusStyle,
svgFill,
themeSpacing,
} from '../../utils/themeUtils'
import Typography, { TypographyProps } from '../Typography'
import IconStyle from '../Icon/IconStyle'
import Typography, { TypographyProps } from '../Typography'

export type LinkVariant = 'inline' | 'blank' | 'with-chevron'

Expand Down Expand Up @@ -42,28 +42,28 @@ export const DefaultLinkStyleCSS = css<Props>`
display: inline-flex;
text-decoration: none;
font-weight: 700;
color: ${({ color: colorOverride, theme }) =>
themeColor('tint', 'level7', colorOverride)({ theme })};
color: ${({ color: colorOverride }) =>
themeColor('tint', 'level7', colorOverride)};

${IconStyle} {
margin: ${themeSpacing(1, 1, 0, 0)};
${({ color: colorOverride, theme, onDarkBackground }) =>
${({ color: colorOverride, onDarkBackground }) =>
onDarkBackground
? svgFill('tint', 'level1')({ theme })
: svgFill('tint', 'level7', colorOverride)({ theme })};
? svgFill(themeColor('tint', 'level1'))
: svgFill(themeColor('tint', 'level7', colorOverride))}
}

&:hover {
text-decoration: underline;
${({ color: colorOverride, theme, onDarkBackground }) =>
${({ color: colorOverride, onDarkBackground }) =>
css`
color: ${onDarkBackground
? themeColor('tint', 'level1')({ theme })
: themeColor('secondary', 'main', colorOverride)({ theme })};
? themeColor('tint', 'level1')
: themeColor('supplement', 'main', colorOverride)};
${IconStyle} {
${onDarkBackground
? svgFill('tint', 'level1')({ theme })
: svgFill('secondary', 'main', colorOverride)({ theme })}
? svgFill(themeColor('tint', 'level1'))
: svgFill(themeColor('secondary', 'main', colorOverride))}
}
`}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const MenuButtonBaseStyle = styled(Button)<Props>`

const activeStyle = css`
color: ${themeColor('secondary')};
${svgFill('secondary')}
${svgFill(themeColor('secondary', 'main'))}

${MenuButtonTextStyle} {
color: ${themeColor('secondary')};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export default styled.a<{

${IconStyle} {
margin-bottom: ${themeSpacing(2)};
${svgFill('tint', 'level7')};
${svgFill(themeColor('tint', 'level7'))};
}
`
4 changes: 0 additions & 4 deletions packages/asc-ui/src/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,3 @@ const HeaderSearchStyle = styled.div`
`
return <HeaderSearchStyle theme={theme} />
```

## svgFill

...
Loading