Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Add ambiance to SecondaryButton
Browse files Browse the repository at this point in the history
  • Loading branch information
arnemolland committed Jan 22, 2022
1 parent 25a74c8 commit 984e9ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 11 additions & 1 deletion docs/buttons/Buttons.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, ButtonProps, IconButton, IconButtonProps } from '../../src'
import { Button, ButtonProps, IconButton, IconButtonProps, Ambiance } from '../../src'
import { Canvas, Meta, ArgsTable, Story } from '@storybook/addon-docs'

<Meta title="Docs/Buttons" component={Button} />
Expand Down Expand Up @@ -48,6 +48,16 @@ Buttons allow users to take actions and make choices. They are used for actions
<Button variant="secondary" size="small" label="Button" />
</Canvas>

### Ambiance

<Canvas>
<Ambiance>
<Button variant="secondary" size="large" label="Button" />
<Button variant="secondary" size="medium" label="Button" />
<Button variant="secondary" size="small" label="Button" />
</Ambiance>
</Canvas>

### Icons

<Canvas>
Expand Down
10 changes: 6 additions & 4 deletions src/lib/components/buttons/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Theme } from '../../../theme'
import React, { ReactNode } from 'react'
import { ButtonContent, ButtonContentProps, StyledButton, StyledButtonProps } from './Button.styles'
import { useTheme } from '../../../hooks'
import { useAmbiance, useTheme } from '../../../hooks'
import { ButtonVariant } from '..'
import { Icon, IconName } from '../../icons'
import chroma from 'chroma-js'

export type IconPosition = 'left' | 'right'

Expand Down Expand Up @@ -43,6 +44,7 @@ export const getButtonMargins = (size: ButtonSize, theme: Theme): ButtonMargins
}

export const getButtonStyles = (props: ButtonProps, theme: Theme): ButtonProps => {
const { color } = useAmbiance()
const { horizontalMargin, verticalMargin } = getButtonMargins(props.size, theme)
const common = {
...props,
Expand All @@ -62,13 +64,13 @@ export const getButtonStyles = (props: ButtonProps, theme: Theme): ButtonProps =
switch (props.variant) {
case 'primary':
return {
backgroundColor: props.backgroundColor ? props.backgroundColor : theme.colors.primary,
foregroundColor: props.foregroundColor ? props.foregroundColor : theme.colors.onPrimary,
backgroundColor: theme.colors.primary,
foregroundColor: theme.colors.onPrimary,
...common
}
case 'secondary':
return {
backgroundColor: theme.colors.secondaryButton,
backgroundColor: color ? chroma(color).saturate(0.4).hex() : theme.colors.secondaryButton,
foregroundColor: theme.colors.onSecondaryButton,
...common
}
Expand Down

0 comments on commit 984e9ac

Please sign in to comment.