Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
feat: added css vars action
Browse files Browse the repository at this point in the history
  • Loading branch information
TheComputerM committed Aug 30, 2020
1 parent c54970d commit 2de2b39
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span slot="icon" let:active>
<Icon
class="mdi mdi-arrow-down-drop-circle-outline"
rotate={active ? '180deg' : '0deg'} />
rotate={active ? 180 : 0} />
</span>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Repellat amet
natus obcaecati molestiae quas mollitia error modi atque aliquam esse.
Expand All @@ -22,15 +22,15 @@
<span slot="icon" let:active>
<Icon
class="mdi mdi-arrow-down-drop-circle"
rotate={active ? '180deg' : '0deg'} />
rotate={active ? 180 : 0 } />
</span>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Repellat amet
natus obcaecati molestiae quas mollitia error modi atque aliquam esse.
</ExpansionPanel>
<ExpansionPanel>
<span slot="header">Item</span>
<span slot="icon" let:active>
<Icon class="mdi mdi-menu-down" rotate={active ? '180deg' : '0deg'} />
<Icon class="mdi mdi-menu-down" rotate={active ? 180 : 0} />
</span>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Repellat amet
natus obcaecati molestiae quas mollitia error modi atque aliquam esse.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<div slot="right">
<Icon
path={mdiChevronDown}
rotate={item.open ? '180deg' : ''}
rotate={item.open ? 180 : 0}
class="chevron" />
</div>
</ListItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<div class="s-expansion-panel__icon">
<!-- Slot for the icon at the right of the header. -->
<slot name="icon" {active}>
<Icon {disabled} path={down} rotate={active ? '180deg' : '0deg'} />
<Icon {disabled} path={down} rotate={active ? 180 : 0} />
</slot>
</div>
</button>
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte-materialify/src/components/Icon/Icon.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.s-icon {
color: var(--theme-icons-active);
font-size: var(--s-icon-size);
transform: rotate(var(--s-icon-rotate));
line-height: 1;
letter-spacing: normal;
text-transform: none;
Expand Down
13 changes: 8 additions & 5 deletions packages/svelte-materialify/src/components/Icon/Icon.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script>
import Style from '../../internal/Style';
let classes = '';
export let disabled = false;
export let size = '24px';
export let rotate = 0;
export let disabled = false;
export let path = null;
export let title = null;
export let rotate = '0deg';
export let style = '';
export let style = null;
export { classes as class };
</script>

Expand All @@ -15,10 +17,11 @@

<i
aria-hidden="true"
style="font-size: {size};transform: rotate({rotate});{style}"
class="s-icon {classes}"
{title}
class:disabled>
class:disabled
use:Style={{ 'icon-size': size, 'icon-rotate': `${rotate}deg` }}
{style}>
{#if path}
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
19 changes: 19 additions & 0 deletions packages/svelte-materialify/src/internal/Style/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function setCustomProperties(node, styles) {
Object.entries(styles).forEach(([key, value]) => {
node.style.setProperty(`--s-${key}`, value);
});
}

/**
* @param node {Element}
* @param styles {Object}
*/
export default (node, styles) => {
setCustomProperties(node, styles);

return {
update(newStyles) {
setCustomProperties(node, newStyles);
},
};
};

0 comments on commit 2de2b39

Please sign in to comment.