Merge pull request #75 from IBM/refactor

refactor(expandable-tile): remove onMount method
This commit is contained in:
Eric Liu 2019-12-24 13:11:33 -08:00 committed by GitHub
commit d874c622f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

View file

@ -6,8 +6,6 @@
export let style = undefined; export let style = undefined;
import { cx } from '../../lib'; import { cx } from '../../lib';
const _class = cx('--skeleton', '--btn', small && '--btn--sm', className);
</script> </script>
{#if href} {#if href}

View file

@ -11,7 +11,7 @@
export let light = false; export let light = false;
export let style = undefined; export let style = undefined;
import { tick, onMount } from 'svelte'; import { tick } 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,20 +19,23 @@
let tileContent = undefined; let tileContent = undefined;
let aboveTheFold = undefined; let aboveTheFold = undefined;
onMount(() => {
const tileStyle = window.getComputedStyle(tile, null);
tileMaxHeight = aboveTheFold.getBoundingClientRect().height;
tilePadding =
parseInt(tileStyle.getPropertyValue('padding-top'), 10) +
parseInt(tileStyle.getPropertyValue('padding-bottom'), 10);
});
async function setHeight() { async function setHeight() {
await tick(); await tick();
tileMaxHeight = expanded tileMaxHeight = expanded
? tileContent.getBoundingClientRect().height ? tileContent.getBoundingClientRect().height
: aboveTheFold.getBoundingClientRect().height; : aboveTheFold.getBoundingClientRect().height;
} }
$: {
if (tile) {
const style = window.getComputedStyle(tile);
tileMaxHeight = aboveTheFold.getBoundingClientRect().height;
tilePadding =
parseInt(style.getPropertyValue('padding-top'), 10) +
parseInt(style.getPropertyValue('padding-bottom'), 10);
}
}
</script> </script>
<div <div
@ -45,8 +48,9 @@
setHeight(); setHeight();
}} }}
on:keypress on:keypress
on:keypress={({ key }) => { on:keypress={event => {
if (key === ' ' || key === 'Enter') { if (event.key === ' ' || event.key === 'Enter') {
event.preventDefault();
expanded = !expanded; expanded = !expanded;
setHeight(); setHeight();
} }