-
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.
feat(core): add
icon
component (#57)
- Loading branch information
1 parent
32853be
commit 7698cc5
Showing
5 changed files
with
109 additions
and
3 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
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,26 @@ | ||
import { newSpecPage } from '@stencil/core/testing' | ||
|
||
import { AtomIcon, CDN_URL } from './icon' | ||
|
||
describe('atom-icon', () => { | ||
it('should render ion-icon element', async () => { | ||
const page = await newSpecPage({ | ||
components: [AtomIcon], | ||
html: `<atom-icon icon="heart" color="primary" size="large"></atom-icon>`, | ||
}) | ||
|
||
if (!page?.root?.shadowRoot) { | ||
throw new Error('page.root is undefined') | ||
} | ||
|
||
await page.waitForChanges() | ||
|
||
expect(page.root).toEqualHtml(` | ||
<atom-icon color="primary" icon="heart" size="large"> | ||
<mock:shadow-root> | ||
<ion-icon color="primary" icon="${CDN_URL}/heart.svg" size="large"></ion-icon> | ||
</mock:shadow-root> | ||
</atom-icon> | ||
`) | ||
}) | ||
}) |
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,55 @@ | ||
import { withActions } from '@storybook/addon-actions/decorator' | ||
import { Meta, StoryObj } from '@storybook/html' | ||
|
||
import { AtomIcon } from './icon' | ||
|
||
type argsIcon = AtomIcon | ||
|
||
export default { | ||
title: 'Ionic Components/Icon', | ||
decorators: [withActions], | ||
argTypes: { | ||
icon: { | ||
control: 'text', | ||
}, | ||
color: { | ||
control: 'select', | ||
options: [ | ||
'primary', | ||
'secondary', | ||
'tertiary', | ||
'success', | ||
'warning', | ||
'danger', | ||
'light', | ||
'medium', | ||
'dark', | ||
], | ||
}, | ||
size: { | ||
control: 'select', | ||
options: ['small', 'large'], | ||
}, | ||
}, | ||
} as Meta<argsIcon> | ||
|
||
type Story = StoryObj<argsIcon> | ||
|
||
const createIcon = (args: argsIcon) => { | ||
return ` | ||
<atom-icon | ||
icon=${args.icon} | ||
color=${args.color} | ||
size=${args.size} | ||
/> | ||
` | ||
} | ||
|
||
export const Default: Story = { | ||
render: (args) => createIcon(args), | ||
args: { | ||
icon: 'heart', | ||
color: 'secondary', | ||
size: 'large', | ||
}, | ||
} |
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,24 @@ | ||
import { Color } from '@ionic/core' | ||
import { Component, Prop, h } from '@stencil/core' | ||
|
||
export const CDN_URL = 'https://unpkg.com/ionicons@7.1.0/dist/ionicons/svg' | ||
|
||
@Component({ | ||
tag: 'atom-icon', | ||
shadow: true, | ||
}) | ||
export class AtomIcon { | ||
@Prop() icon?: string | ||
@Prop() color?: Color | ||
@Prop() size?: 'small' | 'large' | ||
|
||
render() { | ||
return ( | ||
<ion-icon | ||
icon={`${CDN_URL}/${this.icon}.svg`} | ||
color={this.color} | ||
size={this.size} | ||
/> | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { AtomButton } from './components/button/button' | ||
export { AtomCol, AtomGrid, AtomRow } from './components/grid' | ||
export { AtomIcon } from './components/icon/icon' | ||
export { AtomInput } from './components/input/input' | ||
export { AtomSelect } from './components/select/select' |