mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
refactor(expandable-tile): use onMount, afterUpdate methods
This commit is contained in:
parent
d874c622f9
commit
41c096bada
1 changed files with 12 additions and 17 deletions
|
@ -11,7 +11,7 @@
|
||||||
export let light = false;
|
export let light = false;
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
|
||||||
import { tick } from 'svelte';
|
import { onMount, afterUpdate } from 'svelte';
|
||||||
import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16';
|
import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16';
|
||||||
import { cx, css } from '../../lib';
|
import { cx, css } from '../../lib';
|
||||||
|
|
||||||
|
@ -19,23 +19,20 @@
|
||||||
let tileContent = undefined;
|
let tileContent = undefined;
|
||||||
let aboveTheFold = undefined;
|
let aboveTheFold = undefined;
|
||||||
|
|
||||||
async function setHeight() {
|
onMount(() => {
|
||||||
await tick();
|
|
||||||
tileMaxHeight = expanded
|
|
||||||
? tileContent.getBoundingClientRect().height
|
|
||||||
: aboveTheFold.getBoundingClientRect().height;
|
|
||||||
}
|
|
||||||
|
|
||||||
$: {
|
|
||||||
if (tile) {
|
|
||||||
const style = window.getComputedStyle(tile);
|
const style = window.getComputedStyle(tile);
|
||||||
|
|
||||||
tileMaxHeight = aboveTheFold.getBoundingClientRect().height;
|
tileMaxHeight = aboveTheFold.getBoundingClientRect().height;
|
||||||
tilePadding =
|
tilePadding =
|
||||||
parseInt(style.getPropertyValue('padding-top'), 10) +
|
parseInt(style.getPropertyValue('padding-top'), 10) +
|
||||||
parseInt(style.getPropertyValue('padding-bottom'), 10);
|
parseInt(style.getPropertyValue('padding-bottom'), 10);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
afterUpdate(() => {
|
||||||
|
tileMaxHeight = expanded
|
||||||
|
? tileContent.getBoundingClientRect().height
|
||||||
|
: aboveTheFold.getBoundingClientRect().height;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -45,14 +42,12 @@
|
||||||
on:click
|
on:click
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
expanded = !expanded;
|
expanded = !expanded;
|
||||||
setHeight();
|
|
||||||
}}
|
}}
|
||||||
on:keypress
|
on:keypress
|
||||||
on:keypress={event => {
|
on:keypress={event => {
|
||||||
if (event.key === ' ' || event.key === 'Enter') {
|
if (event.key === ' ' || event.key === 'Enter') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
expanded = !expanded;
|
expanded = !expanded;
|
||||||
setHeight();
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:mouseover
|
on:mouseover
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue