Skip to content

Commit

Permalink
Merge pull request #3 from melohagan/main
Browse files Browse the repository at this point in the history
Provide toggle context to children
  • Loading branch information
YuanZhang98 authored Oct 5, 2022
2 parents 8e380cc + f5f90e9 commit ab7b252
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "budibase-toggle",
"version": "2.0.1",
"version": "2.1.0",
"description": "An amazing Budibase component!",
"license": "MIT",
"svelte": "index.js",
Expand Down
17 changes: 17 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"friendlyName": "budibase-toggle",
"description": "An amazing Budibase component!",
"icon": "Text",
"hasChildren": true,
"settings": [
{
"type": "color",
Expand All @@ -25,6 +26,22 @@
"label": "Accent Color",
"defaultValue": "#BAC4C6"
}
],
"context": [
{
"type": "schema"
},
{
"type": "static",
"values": [
{
"label": "Active State",
"key": "isActive",
"type": "boolean",
"defaultValue": false
}
]
}
]
}
}
17 changes: 11 additions & 6 deletions src/Component.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<script>
import { getContext } from "svelte"
const { styleable } = getContext("sdk")
const { styleable, Provider } = getContext("sdk")
const component = getContext("component")
export let inactiveColor;
export let activeColor;
export let accentColor;
let isActive = false;
$: dataContext = {
isActive
}
const handleButtonClick = () => {
isActive = !isActive;
};
</script>

<div use:styleable={$component.styles}>
<div class="toggle">
<div style="background: {isActive ? activeColor : inactiveColor};" class="toggle-button {isActive && 'toggle-button-active'}" on:click={handleButtonClick}>
<div style="background: {accentColor};" class="toggle-inner-circle {isActive && 'toggle-inner-circle-active'}">
<Provider data={dataContext}>
<div class="toggle">
<div style="background: {isActive ? activeColor : inactiveColor};" class="toggle-button {isActive && 'toggle-button-active'}" on:click={handleButtonClick}>
<div style="background: {accentColor};" class="toggle-inner-circle {isActive && 'toggle-inner-circle-active'}">
</div>
</div>
</div>
</div>
<slot />
</Provider>
</div>

<style>
Expand Down

0 comments on commit ab7b252

Please sign in to comment.