mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
refactor(structured-list): make StructuredListWrapper default component
This commit is contained in:
parent
e7bb051cab
commit
0b30250e57
7 changed files with 33 additions and 31 deletions
|
@ -96,7 +96,6 @@ Currently, the following components are supported:
|
||||||
- StructuredListCell
|
- StructuredListCell
|
||||||
- StructuredListRow
|
- StructuredListRow
|
||||||
- StructuredListInput
|
- StructuredListInput
|
||||||
- StructuredListWrapper
|
|
||||||
- Tabs
|
- Tabs
|
||||||
- Tab
|
- Tab
|
||||||
- TabContent
|
- TabContent
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
import StructuredListHead from './StructuredListHead.svelte';
|
import StructuredListHead from './StructuredListHead.svelte';
|
||||||
import StructuredListInput from './StructuredListInput.svelte';
|
import StructuredListInput from './StructuredListInput.svelte';
|
||||||
import StructuredListRow from './StructuredListRow.svelte';
|
import StructuredListRow from './StructuredListRow.svelte';
|
||||||
import StructuredListWrapper from './StructuredListWrapper.svelte';
|
|
||||||
import StructuredListSkeleton from './StructuredList.Skeleton.svelte';
|
import StructuredListSkeleton from './StructuredList.Skeleton.svelte';
|
||||||
|
import StructuredList from './StructuredList.svelte';
|
||||||
|
|
||||||
|
let selected = 'row-1-value';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Layout>
|
<Layout>
|
||||||
|
@ -18,10 +20,9 @@
|
||||||
{#if story === 'skeleton'}
|
{#if story === 'skeleton'}
|
||||||
<div style="width: 800px">
|
<div style="width: 800px">
|
||||||
<StructuredListSkeleton />
|
<StructuredListSkeleton />
|
||||||
<StructuredListSkeleton border />
|
|
||||||
</div>
|
</div>
|
||||||
{:else if story === 'selection'}
|
{:else if story === 'selection'}
|
||||||
<StructuredListWrapper selection border defaultSelected="row-1-value">
|
<StructuredList selection border bind:selected>
|
||||||
<StructuredListHead>
|
<StructuredListHead>
|
||||||
<StructuredListRow head>
|
<StructuredListRow head>
|
||||||
<StructuredListCell head>ColumnA</StructuredListCell>
|
<StructuredListCell head>ColumnA</StructuredListCell>
|
||||||
|
@ -54,9 +55,9 @@
|
||||||
</StructuredListRow>
|
</StructuredListRow>
|
||||||
{/each}
|
{/each}
|
||||||
</StructuredListBody>
|
</StructuredListBody>
|
||||||
</StructuredListWrapper>
|
</StructuredList>
|
||||||
{:else}
|
{:else}
|
||||||
<StructuredListWrapper>
|
<StructuredList>
|
||||||
<StructuredListHead>
|
<StructuredListHead>
|
||||||
<StructuredListRow head>
|
<StructuredListRow head>
|
||||||
<StructuredListCell head>ColumnA</StructuredListCell>
|
<StructuredListCell head>ColumnA</StructuredListCell>
|
||||||
|
@ -84,7 +85,7 @@
|
||||||
</StructuredListCell>
|
</StructuredListCell>
|
||||||
</StructuredListRow>
|
</StructuredListRow>
|
||||||
</StructuredListBody>
|
</StructuredListBody>
|
||||||
</StructuredListWrapper>
|
</StructuredList>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
let className = undefined;
|
let className = undefined;
|
||||||
export { className as class };
|
export { className as class };
|
||||||
export let defaultSelected = undefined;
|
export let selected = undefined;
|
||||||
export let border = false;
|
export let border = false;
|
||||||
export let selection = false;
|
export let selection = false;
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
@ -12,18 +12,18 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
let selected = writable(defaultSelected);
|
let selectedValue = writable(selected);
|
||||||
|
|
||||||
setContext('StructuredListWrapper', {
|
setContext('StructuredListWrapper', {
|
||||||
selected,
|
selectedValue,
|
||||||
update: value => {
|
update: value => {
|
||||||
selected.set(value);
|
selectedValue.set(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$: selected = $selectedValue;
|
||||||
$: {
|
$: {
|
||||||
defaultSelected = $selected;
|
dispatch('change', $selectedValue);
|
||||||
dispatch('change', $selected);
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
class={cx('--structured-list', border && '--structured-list--border', selection && '--structured-list--selection', className)}
|
|
||||||
aria-label={$$props['aria-label'] || 'Structured list section'}
|
aria-label={$$props['aria-label'] || 'Structured list section'}
|
||||||
|
class={cx('--structured-list', border && '--structured-list--border', selection && '--structured-list--selection', className)}
|
||||||
{style}>
|
{style}>
|
||||||
<slot />
|
<slot />
|
||||||
</section>
|
</section>
|
|
@ -1,23 +1,23 @@
|
||||||
<script>
|
<script>
|
||||||
let className = undefined;
|
let className = undefined;
|
||||||
export { className as class };
|
export { className as class };
|
||||||
export let id = Math.random();
|
|
||||||
export let value = 'value';
|
|
||||||
export let title = 'title';
|
|
||||||
export let name = '';
|
|
||||||
export let checked = false;
|
export let checked = false;
|
||||||
|
export let id = Math.random();
|
||||||
|
export let name = '';
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
export let title = 'title';
|
||||||
|
export let value = 'value';
|
||||||
|
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
import { cx } from '../../lib';
|
import { cx } from '../../lib';
|
||||||
|
|
||||||
const { selected, update } = getContext('StructuredListWrapper');
|
const { selectedValue, update } = getContext('StructuredListWrapper');
|
||||||
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
update(value);
|
update(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$: checked = $selected === value;
|
$: checked = $selectedValue === value;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
@ -27,9 +27,9 @@
|
||||||
on:change={() => {
|
on:change={() => {
|
||||||
update(value);
|
update(value);
|
||||||
}}
|
}}
|
||||||
{value}
|
{checked}
|
||||||
{name}
|
|
||||||
{title}
|
|
||||||
{style}
|
|
||||||
{id}
|
{id}
|
||||||
{checked} />
|
{name}
|
||||||
|
{style}
|
||||||
|
{title}
|
||||||
|
{value} />
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
export { className as class };
|
export { className as class };
|
||||||
export let head = false;
|
export let head = false;
|
||||||
export let label = false;
|
export let label = false;
|
||||||
export let tabindex = '0';
|
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
export let tabindex = '0';
|
||||||
|
|
||||||
import { cx } from '../../lib';
|
import { cx } from '../../lib';
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
import StructuredList from './StructuredList.svelte';
|
||||||
|
|
||||||
|
export default StructuredList;
|
||||||
|
|
||||||
export { default as StructuredListSkeleton } from './StructuredList.Skeleton.svelte';
|
export { default as StructuredListSkeleton } from './StructuredList.Skeleton.svelte';
|
||||||
export { default as StructuredListBody } from './StructuredListBody.svelte';
|
export { default as StructuredListBody } from './StructuredListBody.svelte';
|
||||||
export { default as StructuredListHead } from './StructuredListHead.svelte';
|
export { default as StructuredListHead } from './StructuredListHead.svelte';
|
||||||
export { default as StructuredListCell } from './StructuredListCell.svelte';
|
export { default as StructuredListCell } from './StructuredListCell.svelte';
|
||||||
export { default as StructuredListRow } from './StructuredListRow.svelte';
|
export { default as StructuredListRow } from './StructuredListRow.svelte';
|
||||||
export { default as StructuredListInput } from './StructuredListInput.svelte';
|
export { default as StructuredListInput } from './StructuredListInput.svelte';
|
||||||
export { default as StructuredListWrapper } from './StructuredListWrapper.svelte';
|
|
||||||
|
|
|
@ -57,14 +57,13 @@ import Select, { SelectSkeleton, SelectItem, SelectItemGroup } from './component
|
||||||
import SkeletonPlaceholder from './components/SkeletonPlaceholder';
|
import SkeletonPlaceholder from './components/SkeletonPlaceholder';
|
||||||
import SkeletonText from './components/SkeletonText';
|
import SkeletonText from './components/SkeletonText';
|
||||||
import Slider, { SliderSkeleton } from './components/Slider';
|
import Slider, { SliderSkeleton } from './components/Slider';
|
||||||
import {
|
import StructuredList, {
|
||||||
StructuredListSkeleton,
|
StructuredListSkeleton,
|
||||||
StructuredListBody,
|
StructuredListBody,
|
||||||
StructuredListHead,
|
StructuredListHead,
|
||||||
StructuredListCell,
|
StructuredListCell,
|
||||||
StructuredListRow,
|
StructuredListRow,
|
||||||
StructuredListInput,
|
StructuredListInput
|
||||||
StructuredListWrapper
|
|
||||||
} from './components/StructuredList';
|
} from './components/StructuredList';
|
||||||
import Tabs, { Tab, TabContent, TabsSkeleton } from './components/Tabs';
|
import Tabs, { Tab, TabContent, TabsSkeleton } from './components/Tabs';
|
||||||
import Tag, { TagSkeleton } from './components/Tag';
|
import Tag, { TagSkeleton } from './components/Tag';
|
||||||
|
@ -159,13 +158,13 @@ export {
|
||||||
Switch,
|
Switch,
|
||||||
Slider,
|
Slider,
|
||||||
SliderSkeleton,
|
SliderSkeleton,
|
||||||
|
StructuredList,
|
||||||
StructuredListSkeleton,
|
StructuredListSkeleton,
|
||||||
StructuredListBody,
|
StructuredListBody,
|
||||||
StructuredListHead,
|
StructuredListHead,
|
||||||
StructuredListCell,
|
StructuredListCell,
|
||||||
StructuredListRow,
|
StructuredListRow,
|
||||||
StructuredListInput,
|
StructuredListInput,
|
||||||
StructuredListWrapper,
|
|
||||||
Tabs,
|
Tabs,
|
||||||
Tab,
|
Tab,
|
||||||
TabContent,
|
TabContent,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue