mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
feat(code-snippet): add skeleton state
This commit is contained in:
parent
62719c45cc
commit
fd7164a312
1 changed files with 66 additions and 56 deletions
|
@ -10,6 +10,7 @@
|
||||||
export let light = false;
|
export let light = false;
|
||||||
export let showLessText = 'Show less';
|
export let showLessText = 'Show less';
|
||||||
export let showMoreText = 'Show more';
|
export let showMoreText = 'Show more';
|
||||||
|
export let skeleton = false;
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
export let type = 'single';
|
export let type = 'single';
|
||||||
|
|
||||||
|
@ -19,19 +20,27 @@
|
||||||
import Button from '../Button';
|
import Button from '../Button';
|
||||||
import Copy from '../Copy';
|
import Copy from '../Copy';
|
||||||
import CopyButton from '../CopyButton';
|
import CopyButton from '../CopyButton';
|
||||||
|
import CodeSnippetSkeleton from './CodeSnippet.Skeleton.svelte';
|
||||||
|
|
||||||
let codeRef = undefined;
|
let codeRef = undefined;
|
||||||
let expanded = false;
|
let expanded = false;
|
||||||
let showMoreLess = false;
|
let showMoreLess = false;
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
showMoreLess = type === 'multi' && codeRef.getBoundingClientRect().height > 255;
|
if (type === 'multi' && codeRef) {
|
||||||
|
showMoreLess = codeRef.getBoundingClientRect().height > 255;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$: expandText = expanded ? showLessText : showMoreText;
|
$: expandText = expanded ? showLessText : showMoreText;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if type === 'inline'}
|
{#if skeleton}
|
||||||
|
<CodeSnippetSkeleton class={className} {type} {style} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if !skeleton}
|
||||||
|
{#if type === 'inline'}
|
||||||
<Copy
|
<Copy
|
||||||
aria-label={$$props['aria-label'] || copyLabel}
|
aria-label={$$props['aria-label'] || copyLabel}
|
||||||
aria-describedby={id}
|
aria-describedby={id}
|
||||||
|
@ -47,7 +56,7 @@
|
||||||
<slot>{code}</slot>
|
<slot>{code}</slot>
|
||||||
</code>
|
</code>
|
||||||
</Copy>
|
</Copy>
|
||||||
{:else}
|
{:else}
|
||||||
<div
|
<div
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
|
@ -86,4 +95,5 @@
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue