-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
/* THIS IS GENERATED CODE. Any changes you make will be overwritten! */ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
|
||
.cds-box { | ||
border-width: var(--cds-border-width-none); | ||
} | ||
.cds-box--primary-default { | ||
background-color: var(--cds-background-primary-default); | ||
} | ||
.cds-box--primary-subtle { | ||
background-color: var(--cds-background-primary-subtle); | ||
} | ||
.cds-box--primary-amplified { | ||
background-color: var(--cds-background-primary-amplified); | ||
} | ||
.cds-box--accent-default { | ||
background-color: var(--cds-background-accent-default); | ||
} | ||
.cds-box--accent-subtle { | ||
background-color: var(--cds-background-accent-subtle); | ||
} | ||
.cds-box--accent-amplified { | ||
background-color: var(--cds-background-accent-amplified); | ||
} | ||
.cds-box--secondary-default { | ||
background-color: var(--cds-background-secondary-default); | ||
} | ||
.cds-box--secondary-subtle { | ||
background-color: var(--cds-background-secondary-subtle); | ||
} | ||
.cds-box--secondary-amplified { | ||
background-color: var(--cds-background-secondary-amplified); | ||
} | ||
.cds-box--neutral-default { | ||
background-color: var(--cds-background-neutral-default); | ||
} | ||
.cds-box--neutral-subtle { | ||
background-color: var(--cds-background-neutral-subtle); | ||
} | ||
.cds-box--neutral-amplified { | ||
background-color: var(--cds-background-neutral-amplified); | ||
} | ||
.cds-box--border { | ||
border-color: var(--cds-border-color-neutral); | ||
border-width: var(--cds-badge-border-width); | ||
border-style: solid; | ||
} | ||
.cds-box--border-square { | ||
border-radius: var(--cds-border-width-none); | ||
} | ||
.cds-box--border-rounded { | ||
border-radius: var(--cds-border-radius-rounded); | ||
} | ||
.cds-box--border-circle { | ||
border-radius: var(--cds-border-radius-circle); | ||
} | ||
.cds-box--border-primary { | ||
border-color: var(--cds-border-color-primary); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.cds-box { | ||
// BACKGROUND COLORS | ||
|
||
&--primary { | ||
&-default { | ||
background-color: var(--cds-background-primary-default); | ||
} | ||
&-subtle { | ||
background-color: var(--cds-background-primary-subtle); | ||
} | ||
&-amplified { | ||
background-color: var(--cds-background-primary-amplified); | ||
} | ||
} | ||
|
||
&--accent { | ||
&-default { | ||
background-color: var(--cds-background-accent-default); | ||
} | ||
&-subtle { | ||
background-color: var(--cds-background-accent-subtle); | ||
} | ||
&-amplified { | ||
background-color: var(--cds-background-accent-amplified); | ||
} | ||
} | ||
|
||
&--secondary { | ||
&-default { | ||
background-color: var(--cds-background-secondary-default); | ||
} | ||
&-subtle { | ||
background-color: var(--cds-background-secondary-subtle); | ||
} | ||
&-amplified { | ||
background-color: var(--cds-background-secondary-amplified); | ||
} | ||
} | ||
|
||
&--neutral { | ||
&-default { | ||
background-color: var(--cds-background-neutral-default); | ||
} | ||
&-subtle { | ||
background-color: var(--cds-background-neutral-subtle); | ||
} | ||
&-amplified { | ||
background-color: var(--cds-background-neutral-amplified); | ||
} | ||
} | ||
|
||
// BORDERS | ||
|
||
border-width: var(--cds-border-width-none); | ||
|
||
&--border { | ||
border-color: var(--cds-border-color-neutral); | ||
border-width: var(--cds-badge-border-width); | ||
border-style: solid; | ||
|
||
&-square { | ||
border-radius: var(--cds-border-width-none); | ||
} | ||
|
||
&-rounded { | ||
border-radius: var(--cds-border-radius-rounded); | ||
} | ||
|
||
&-circle { | ||
border-radius: var(--cds-border-radius-circle); | ||
} | ||
|
||
&-primary { | ||
border-color: var(--cds-border-color-primary); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import './box.scss'; | ||
import '../TextBox/textBox.scss'; | ||
|
||
export default { | ||
title: 'Components/Box', | ||
argTypes: { | ||
backgroundColor: { | ||
control: { type: 'select' }, | ||
options: ['primary', 'secondary', 'accent', 'neutral'], | ||
}, | ||
backgroundTint: { | ||
control: { type: 'select' }, | ||
options: ['default', 'subtle', 'amplified'], | ||
}, | ||
borderRadius: { | ||
control: { type: 'select' }, | ||
options: ['square', 'rounded', 'circle'], | ||
}, | ||
borderColor: { | ||
control: { type: 'select' }, | ||
options: ['default', 'primary'], | ||
}, | ||
textColor: { | ||
control: { type: 'select' }, | ||
options: ['default', 'primary', 'white', 'accent'], | ||
}, | ||
isMobile: { | ||
control: 'boolean', | ||
}, | ||
}, | ||
decorators: [ | ||
(story) => { | ||
const wrapperDiv = document.createElement('div'); | ||
wrapperDiv.setAttribute('style', 'background-color: #fff; padding: 50px'); | ||
wrapperDiv.appendChild(story()); | ||
return wrapperDiv; | ||
}, | ||
], | ||
}; | ||
|
||
const defaultBoxContent = ` | ||
<div style="padding: 30px"> | ||
<h1>Heading 1</h1> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
</div> | ||
`; | ||
|
||
const createBox = ({ | ||
backgroundColor = 'neutral', | ||
backgroundTint = 'default', | ||
borderRadius, | ||
borderColor, | ||
textColor = 'default', | ||
isMobile = false, | ||
}) => { | ||
const box = document.createElement('div'); | ||
box.className = 'cds-box'; | ||
box.classList.add(`cds-box--${backgroundColor}-${backgroundTint}`); | ||
if (borderRadius || borderColor) { | ||
box.classList.add(`cds-box--border`); | ||
box.classList.add(`cds-box--border-${borderRadius || 'square'}`); | ||
if (borderColor !== 'default') { | ||
box.classList.add(`cds-box--border-${borderColor || 'default'}`); | ||
} | ||
} | ||
|
||
box.classList.add('cds-text-box'); | ||
box.classList.add(`cds-text-box--${textColor}`); | ||
if (!isMobile) { | ||
box.classList.add('cds-text-box--desktop'); | ||
} | ||
|
||
box.innerHTML = defaultBoxContent; | ||
return box; | ||
}; | ||
|
||
const Template = (args) => { | ||
return createBox(args); | ||
}; | ||
|
||
export const Default = Template.bind({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Meta } from '@storybook/react'; | ||
import Box from './Box'; | ||
|
||
const meta: Meta<typeof Box> = { | ||
title: 'Components/Box', | ||
component: Box, | ||
}; | ||
|
||
export default meta; | ||
|
||
const defaultCardContent = ( | ||
<div style={{ padding: '30px' }}> | ||
<h1>Heading 1</h1> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim | ||
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea | ||
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate | ||
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat | ||
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id | ||
est laborum. | ||
</p> | ||
</div> | ||
); | ||
|
||
export const Default = { | ||
argTypes: { | ||
backgroundColor: { | ||
control: { type: 'select' }, | ||
}, | ||
backgroundTint: { | ||
control: { type: 'select' }, | ||
}, | ||
addBorder: { | ||
control: { type: 'boolean' }, | ||
}, | ||
borderRadius: { | ||
control: { type: 'select' }, | ||
}, | ||
borderColor: { | ||
control: { type: 'select' }, | ||
}, | ||
isMobile: { | ||
control: { type: 'boolean' }, | ||
}, | ||
textColor: { | ||
control: { type: 'select' }, | ||
}, | ||
}, | ||
|
||
args: { | ||
children: defaultCardContent, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { render } from '@testing-library/react'; | ||
import Box from './Box'; | ||
|
||
describe('Box', () => { | ||
it('should render default props correctly', () => { | ||
const { container } = render(<Box>Default Box</Box>); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('should add the correct background color classes', () => { | ||
const { container } = render( | ||
<Box backgroundColor="primary" backgroundTint="subtle"> | ||
Default Box | ||
</Box>, | ||
); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('should add the correct border classes', () => { | ||
const { container } = render( | ||
<Box borderColor="primary" borderRadius="rounded"> | ||
Default Box | ||
</Box>, | ||
); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('should add the correct text color class', () => { | ||
const { container } = render(<Box textColor="accent">Default Box</Box>); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('should add the given classname', () => { | ||
const { container } = render( | ||
<Box className="testClassName">Default Box</Box>, | ||
); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ReactNode } from 'react'; | ||
import { getClasses } from '../../utils/classes'; | ||
import textStyles from '@compassion-design-system/core/src/components/TextBox/textBox.module.css'; | ||
import boxStyles from '@compassion-design-system/core/src/components/Box/box.module.css'; | ||
|
||
export interface BoxProps { | ||
children: ReactNode; | ||
backgroundColor?: 'primary' | 'secondary' | 'accent' | 'neutral'; | ||
backgroundTint?: 'default' | 'subtle' | 'amplified'; | ||
borderRadius?: 'square' | 'rounded' | 'circle'; | ||
borderColor?: 'default' | 'primary'; | ||
isMobile?: boolean; | ||
textColor?: 'default' | 'primary' | 'white' | 'accent'; | ||
className?: string; | ||
} | ||
|
||
const Box = ({ | ||
children, | ||
isMobile = false, | ||
textColor = 'default', | ||
backgroundColor = 'neutral', | ||
backgroundTint = 'default', | ||
borderRadius, | ||
borderColor, | ||
className, | ||
}: BoxProps) => { | ||
const boxClasses = [ | ||
textStyles['cds-text-box'], | ||
textStyles[`cds-text-box--${textColor}`], | ||
boxStyles['cds-box'], | ||
boxStyles[`cds-box--${backgroundColor}-${backgroundTint}`], | ||
]; | ||
|
||
if (borderRadius || borderColor) { | ||
boxClasses.push(boxStyles['cds-box--border']); | ||
boxClasses.push(boxStyles[`cds-box--border-${borderRadius || 'square'}`]); | ||
borderColor !== 'default' && | ||
boxClasses.push( | ||
boxStyles[`cds-box--border-${borderColor || 'default'}}`], | ||
); | ||
} | ||
|
||
if (!isMobile) { | ||
boxClasses.push(textStyles['cds-text-box--desktop']); | ||
} | ||
return ( | ||
<div id="box" className={getClasses(textStyles, boxClasses, className)}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Box; |
Oops, something went wrong.