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

Feat #30 - Toggle and Icon components #52

Merged
merged 22 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
eb42821
Feat #30 - Add Toggle component, refac
sam-dassana Aug 19, 2020
cf2d94d
Feat #30 - Add icon component
sam-dassana Aug 20, 2020
f1f5d13
Feat #30 - Adress PR comments
sam-dassana Aug 20, 2020
240a4f1
Feat #30 - Fix relative Urls
sam-dassana Aug 20, 2020
c4f9dfd
Feat #30 - Add components to index.ts for export
sam-dassana Aug 20, 2020
a55f263
Feat #30 - Update tsconfig.rollup.json
sam-dassana Aug 20, 2020
3683a7d
Feat #30 - Address PR comments
sam-dassana Aug 20, 2020
45fb102
Feat #30 - Update Link, Icon conditional props, address PR comments
sam-dassana Aug 21, 2020
d03732a
Update src/components/Icon/index.tsx
parth-dassana Aug 21, 2020
4a41517
Feat #30 - Delete Table
sam-dassana Aug 21, 2020
799b1fa
Feat #30 - Add Toggle component, refac
sam-dassana Aug 19, 2020
6c5e5f9
Feat #30 - Add icon component
sam-dassana Aug 20, 2020
9a48102
Feat #30 - Adress PR comments
sam-dassana Aug 20, 2020
80c6afc
Feat #30 - Fix relative Urls
sam-dassana Aug 20, 2020
513c7bc
Feat #30 - Add components to index.ts for export
sam-dassana Aug 20, 2020
6b65346
Feat #30 - Update tsconfig.rollup.json
sam-dassana Aug 20, 2020
eeb9bf0
Feat #30 - Address PR comments
sam-dassana Aug 20, 2020
a97600c
Feat #30 - Update Link, Icon conditional props, address PR comments
sam-dassana Aug 21, 2020
a7317a6
Update src/components/Icon/index.tsx
parth-dassana Aug 21, 2020
e5c2f43
Feat #30 - Delete Table
sam-dassana Aug 21, 2020
a27fc64
Update snapshots after rebase
sam-dassana Aug 21, 2020
e1e0cda
Merge branch 'web-components' of github.com:dassana-io/web-components…
sam-dassana Aug 21, 2020
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
83 changes: 83 additions & 0 deletions src/__snapshots__/storybook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ exports[`Storyshots Button Primary Disabled 1`] = `
</button>
`;

exports[`Storyshots Icon AWS 1`] = `
<img
alt="aws-logo"
height={64}
src="aws.svg"
width={64}
/>
`;

exports[`Storyshots Icon Dassana Blue 1`] = `
<img
alt="dassana-blue"
height={64}
src="dassana-blue.png"
width={64}
/>
`;

exports[`Storyshots Icon Dassana Orange 1`] = `
<img
alt="dassana-orange"
height={32}
src="dassana-orange.png"
width={32}
/>
`;

exports[`Storyshots Link Default 1`] = `
<a
className="ant-typography"
Expand Down Expand Up @@ -141,3 +168,59 @@ exports[`Storyshots Tag Default 1`] = `
Default
</span>
`;

exports[`Storyshots Toggle Checked Disabled 1`] = `
<button
aria-checked={true}
className="ant-switch ant-switch-checked ant-switch-disabled"
disabled={true}
onClick={[Function]}
onKeyDown={[Function]}
role="switch"
type="button"
>
<div
className="ant-switch-handle"
/>
<span
className="ant-switch-inner"
/>
</button>
`;

exports[`Storyshots Toggle Default 1`] = `
<button
aria-checked={true}
className="ant-switch ant-switch-checked"
onClick={[Function]}
onKeyDown={[Function]}
role="switch"
type="button"
>
<div
className="ant-switch-handle"
/>
<span
className="ant-switch-inner"
/>
</button>
`;

exports[`Storyshots Toggle Disabled 1`] = `
<button
aria-checked={false}
className="ant-switch ant-switch-disabled"
disabled={true}
onClick={[Function]}
onKeyDown={[Function]}
role="switch"
type="button"
>
<div
className="ant-switch-handle"
/>
<span
className="ant-switch-inner"
/>
</button>
`;
2 changes: 1 addition & 1 deletion src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import Button, { ButtonProps } from './index'
import Button, { ButtonProps } from '.'
import { shallow, ShallowWrapper } from 'enzyme'

let wrapper: ShallowWrapper<ButtonProps>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ButtonProps {
primary?: boolean
/**
* Adds the disabled attribute and styles (opacity, gray scale filter, no pointer events).
* */
*/
disabled?: boolean
/**
* Array of classes to pass to button.
Expand Down
27 changes: 27 additions & 0 deletions src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import Icon, { IconProps } from '.'
import { Meta, Story } from '@storybook/react/types-6-0'

export default {
component: Icon,
title: 'Icon'
} as Meta

const Template: Story<IconProps> = args => <Icon {...args} />

export const DassanaBlue = Template.bind({})
DassanaBlue.args = {
icon: 'dassana-blue',
size: 64
}

export const DassanaOrange = Template.bind({})
DassanaOrange.args = {
icon: 'dassana-orange'
}

export const AWS = Template.bind({})
AWS.args = {
icon: 'aws-logo',
size: 64
}
parth-dassana marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions src/components/Icon/Icon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import Icon, { IconProps } from '.'
import { mount, ReactWrapper } from 'enzyme'

let wrapper: ReactWrapper
const mockProps: IconProps = {
sam-dassana marked this conversation as resolved.
Show resolved Hide resolved
icon: 'dassana-blue',
size: 64
}

beforeEach(() => {
wrapper = mount(<Icon {...mockProps} />)
})

describe('Icon', () => {
it('renders', () => {
expect(wrapper).toHaveLength(1)
})

it('renders with correct src url', () => {
expect(wrapper.getDOMNode().getAttribute('src')).toContain(
'dassana-blue'
)
})

it('has the correct alt attribute', () => {
expect(wrapper.getDOMNode().getAttribute('alt')).toBe('dassana-blue')
})

it('has the correct size', () => {
expect(wrapper.getDOMNode().getAttribute('height')).toBe('64')
expect(wrapper.getDOMNode().getAttribute('width')).toBe('64')
})
})
61 changes: 61 additions & 0 deletions src/components/Icon/icons/aws.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/components/Icon/icons/dassana-blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/components/Icon/icons/dassana-orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/components/Icon/icons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import AWS from './aws.svg'
import DASSANA_BLUE from './dassana-blue.png'
import DASSANA_ORANGE from './dassana-orange.png'

const Icons = {
'aws-logo': AWS,
'dassana-blue': DASSANA_BLUE,
'dassana-orange': DASSANA_ORANGE
}

export type IconName = keyof typeof Icons

export default Icons
19 changes: 19 additions & 0 deletions src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Icons, { IconName } from './icons'
import React, { FC } from 'react'

export interface IconProps {
/**
* The name of the icon.
*/
icon: IconName
/**
* The width and height of the icon, in pixels.
*/
size?: number
}

const Icon: FC<IconProps> = ({ icon, size = 32 }: IconProps) => {
return <img alt={icon} height={size} src={Icons[icon]} width={size} />
sam-dassana marked this conversation as resolved.
Show resolved Hide resolved
}

export default Icon
2 changes: 1 addition & 1 deletion src/components/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action } from '@storybook/addon-actions'
import React from 'react'
import Link, { LinkProps } from './index'
import Link, { LinkProps } from '.'
import { Meta, Story } from '@storybook/react/types-6-0'

export default {
Expand Down
14 changes: 6 additions & 8 deletions src/components/Link/Link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@ beforeEach(() => {

describe('Link', () => {
it('renders', () => {
const link = wrapper.find(Link)
expect(link).toHaveLength(1)
expect(wrapper).toHaveLength(1)
})

it('calls onClick function when link is clicked', () => {
const link = wrapper.find(Link)
link.simulate('click')
wrapper.simulate('click')
expect(mockClick).toHaveBeenCalledTimes(1)
})

it('has the correct href attribute', () => {
const link = wrapper.find(Link)
expect(link.getDOMNode().getAttribute('href')).toBe(mockProps.href)
expect(wrapper.getDOMNode().getAttribute('href')).toBe(mockProps.href)
})

it('has the correct target attribute', () => {
const link = wrapper.find(Link)
expect(link.getDOMNode().getAttribute('target')).toBe(mockProps.target)
expect(wrapper.getDOMNode().getAttribute('target')).toBe(
mockProps.target
)
})

it('throws an error if both onClick and href props are undefined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Meta, Story } from '@storybook/react/types-6-0'
import Tag, { TagProps } from './index'
import Tag, { TagProps } from '.'

export default {
argTypes: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tag/Tag.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { shallow, ShallowWrapper } from 'enzyme'
import Tag, { TagProps } from './index'
import Tag, { TagProps } from '.'

let wrapper: ShallowWrapper<TagProps>

Expand Down
27 changes: 27 additions & 0 deletions src/components/Toggle/Toggle.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import { Meta, Story } from '@storybook/react/types-6-0'
import Toggle, { ToggleProps } from '.'

export default {
component: Toggle,
title: 'Toggle'
} as Meta

const Template: Story<ToggleProps> = args => <Toggle {...args} />

export const Default = Template.bind({})
Default.args = {
defaultChecked: true
}

export const Disabled = Template.bind({})
Disabled.args = {
defaultChecked: false,
sam-dassana marked this conversation as resolved.
Show resolved Hide resolved
disabled: true
}

export const CheckedDisabled = Template.bind({})
CheckedDisabled.args = {
defaultChecked: true,
disabled: true
}
31 changes: 31 additions & 0 deletions src/components/Toggle/Toggle.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'
import { mount, ReactWrapper } from 'enzyme'
import Toggle, { ToggleProps } from '.'

let wrapper: ReactWrapper
const mockProps: ToggleProps = {
defaultChecked: false
}

beforeEach(() => {
wrapper = mount(<Toggle {...mockProps} />)
})

describe('Toggle', () => {
it('renders', () => {
expect(wrapper).toHaveLength(1)
})

it('has the correct role attribute', () => {
expect(wrapper.getDOMNode().getAttribute('role')).toBe('switch')
})

it('has the correct aria-checked attribute', () => {
expect(wrapper.getDOMNode().getAttribute('aria-checked')).toBe('false')
})

it('changes the aria-checked attribute when it is clicked', () => {
wrapper.simulate('click')
expect(wrapper.getDOMNode().getAttribute('aria-checked')).toBe('true')
})
})
Loading