mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-16 02:41:05 +00:00
feat: initial commit
This commit is contained in:
parent
bde7dd644f
commit
72dc38ea56
119 changed files with 14925 additions and 1 deletions
10
src/components/SkeletonText/SkeletonText.Story.svelte
Normal file
10
src/components/SkeletonText/SkeletonText.Story.svelte
Normal file
|
@ -0,0 +1,10 @@
|
|||
<script>
|
||||
import Layout from '../../internal/ui/Layout.svelte';
|
||||
import SkeletonText from './SkeletonText.svelte';
|
||||
</script>
|
||||
|
||||
<Layout>
|
||||
<div style="width: 300px">
|
||||
<SkeletonText {...$$props} />
|
||||
</div>
|
||||
</Layout>
|
18
src/components/SkeletonText/SkeletonText.stories.js
Normal file
18
src/components/SkeletonText/SkeletonText.stories.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { withKnobs, select, boolean, number } from '@storybook/addon-knobs';
|
||||
import Component from './SkeletonText.Story.svelte';
|
||||
|
||||
export default { title: 'SkeletonText', decorators: [withKnobs] };
|
||||
|
||||
export const Default = () => ({
|
||||
Component,
|
||||
props: {
|
||||
heading: boolean('Skeleton text at a larger size (heading)'),
|
||||
paragraph: boolean('Use multiple lines of text (paragraph)'),
|
||||
lineCount: number('The number of lines in a paragraph (lineCount)', 3),
|
||||
width: select(
|
||||
'Width (in px or %) of single line of text or max-width of paragraph lines (width)',
|
||||
{ '100%': '100%', '250px': '250px' },
|
||||
'100%'
|
||||
)
|
||||
}
|
||||
});
|
37
src/components/SkeletonText/SkeletonText.svelte
Normal file
37
src/components/SkeletonText/SkeletonText.svelte
Normal file
|
@ -0,0 +1,37 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let paragraph = false;
|
||||
export let lineCount = 3;
|
||||
export let width = '100%';
|
||||
export let heading = false;
|
||||
export let props = {};
|
||||
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const randoms = [0.973051493507435, 0.15334737213558558, 0.5671034553053769];
|
||||
const _class = cx('--skeleton__text', heading && '--skeleton__heading', className);
|
||||
const widthNum = parseInt(width, 10);
|
||||
const widthPx = width.includes('px');
|
||||
const widthPercent = width.includes('%');
|
||||
let lines = [];
|
||||
|
||||
$: if (paragraph) {
|
||||
for (let i = 0; i < lineCount; i++) {
|
||||
const min = widthPx ? widthNum - 75 : 0;
|
||||
const max = widthPx ? widthNum : 75;
|
||||
const randomWidth = Math.floor(randoms[i % 3] * (max - min + 1)) + min + 'px';
|
||||
lines = [...lines, { width: widthPx ? randomWidth : `calc(${width} - ${randomWidth})` }];
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if paragraph}
|
||||
<div>
|
||||
{#each lines as { width }}
|
||||
<p {...props} class={_class} style={`width: ${width};`} />
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p {...props} class={_class} style={`width: ${width};`} />
|
||||
{/if}
|
3
src/components/SkeletonText/index.js
Normal file
3
src/components/SkeletonText/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import SkeletonText from './SkeletonText.svelte';
|
||||
|
||||
export default SkeletonText;
|
Loading…
Add table
Add a link
Reference in a new issue