mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-16 19:01:05 +00:00
feat: initial commit
This commit is contained in:
parent
bde7dd644f
commit
72dc38ea56
119 changed files with 14925 additions and 1 deletions
5
src/components/Tag/Tag.Skeleton.svelte
Normal file
5
src/components/Tag/Tag.Skeleton.svelte
Normal file
|
@ -0,0 +1,5 @@
|
|||
<script>
|
||||
import { cx } from '../../lib';
|
||||
</script>
|
||||
|
||||
<span class={cx('--tag', '--skeleton')} />
|
23
src/components/Tag/Tag.Story.svelte
Normal file
23
src/components/Tag/Tag.Story.svelte
Normal file
|
@ -0,0 +1,23 @@
|
|||
<script>
|
||||
export let story = undefined;
|
||||
export let type = undefined;
|
||||
export let disabled = undefined;
|
||||
export let filter = undefined;
|
||||
export let slot = undefined;
|
||||
|
||||
import Layout from '../../internal/ui/Layout.svelte';
|
||||
import Tag from './Tag.svelte';
|
||||
import TagSkeleton from './Tag.Skeleton.svelte';
|
||||
</script>
|
||||
|
||||
<Layout>
|
||||
<div>
|
||||
{#if story === 'filter'}
|
||||
<Tag {filter}>{slot}</Tag>
|
||||
{:else if story === 'skeleton'}
|
||||
<TagSkeleton />
|
||||
{:else}
|
||||
<Tag {disabled} {type}>{slot}</Tag>
|
||||
{/if}
|
||||
</div>
|
||||
</Layout>
|
29
src/components/Tag/Tag.stories.js
Normal file
29
src/components/Tag/Tag.stories.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { withKnobs, select, boolean, text } from '@storybook/addon-knobs';
|
||||
import Component from './Tag.Story.svelte';
|
||||
import { TYPES } from './constants';
|
||||
|
||||
export default { title: 'Tag', decorators: [withKnobs] };
|
||||
|
||||
export const Default = () => ({
|
||||
Component,
|
||||
props: {
|
||||
type: select(
|
||||
'Tag type (type)',
|
||||
Object.keys(TYPES).reduce((items, item) => ({ ...items, [`${item} (${item})`]: item }), {}),
|
||||
'red'
|
||||
),
|
||||
disabled: boolean('Disabled (disabled)', false),
|
||||
slot: text('Content ($$slot)', 'This is not a tag')
|
||||
}
|
||||
});
|
||||
|
||||
export const Filter = () => ({
|
||||
Component,
|
||||
props: {
|
||||
story: 'filter',
|
||||
filter: true,
|
||||
slot: text('Content ($$slot)', 'This is not a tag')
|
||||
}
|
||||
});
|
||||
|
||||
export const Skeleton = () => ({ Component, props: { story: 'skeleton' } });
|
40
src/components/Tag/Tag.svelte
Normal file
40
src/components/Tag/Tag.svelte
Normal file
|
@ -0,0 +1,40 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let type = undefined;
|
||||
export let disabled = false;
|
||||
export let filter = false;
|
||||
export let title = 'Clear filter';
|
||||
export let props = {};
|
||||
|
||||
import Close16 from 'carbon-icons-svelte/lib/Close16';
|
||||
import { cx } from '../../lib';
|
||||
import { TYPES } from './constants';
|
||||
|
||||
const _class = cx(
|
||||
'--tag',
|
||||
type && `--tag--${type}`,
|
||||
disabled && '--tag--disabled',
|
||||
filter && '--tag--filter',
|
||||
className
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if filter}
|
||||
<span
|
||||
{...props}
|
||||
tabindex="0"
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
class={_class}
|
||||
{title}>
|
||||
<slot>{TYPES[type]}</slot>
|
||||
<Close16 aria-label={title} />
|
||||
</span>
|
||||
{:else}
|
||||
<span {...props} on:click on:mouseover on:mouseenter on:mouseleave class={_class}>
|
||||
<slot>{TYPES[type]}</slot>
|
||||
</span>
|
||||
{/if}
|
12
src/components/Tag/constants.js
Normal file
12
src/components/Tag/constants.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
export const TYPES = {
|
||||
red: 'Red',
|
||||
magenta: 'Magenta',
|
||||
purple: 'Purple',
|
||||
blue: 'Blue',
|
||||
cyan: 'Cyan',
|
||||
teal: 'Teal',
|
||||
green: 'Green',
|
||||
gray: 'Gray',
|
||||
'cool-gray': 'Cool-Gray',
|
||||
'warm-gray': 'Warm-Gray'
|
||||
};
|
4
src/components/Tag/index.js
Normal file
4
src/components/Tag/index.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import Tag from './Tag.svelte';
|
||||
|
||||
export default Tag;
|
||||
export { default as TagSkeleton } from './Tag.Skeleton.svelte';
|
Loading…
Add table
Add a link
Reference in a new issue