Skip to content

Commit

Permalink
add disabled/readonly setting
Browse files Browse the repository at this point in the history
  • Loading branch information
andz-bb committed Apr 20, 2023
1 parent 9e2369b commit e8b609d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "star-rating",
"version": "1.1.0",
"version": "1.2.0",
"description": "A five star component :)",
"author": "andz-bb",
"license": "MIT",
Expand Down
7 changes: 7 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"schema": {
"name": "star-rating",
"friendlyName": "Rating",
"requiredAncestors": ["form"],
"description": "A five star component ⭐️",
"icon": "Star",
"showSettingsBar": true,
Expand All @@ -27,6 +28,12 @@
"min": 1,
"max": 20
},
{
"type": "boolean",
"label": "Disabled",
"key": "disabled",
"defaultValue": false
},
{
"type": "select",
"label": "Size",
Expand Down
10 changes: 6 additions & 4 deletions src/Component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Icon from "./Icon.svelte";
export let color;
export let disabled;
export let field;
export let label;
Expand All @@ -19,6 +20,7 @@
const formStepContext = getContext("form-step");
const fieldGroupContext = getContext("field-group");
let defaultValue = disabled ? null : 0;
let fieldApi;
let fieldState;
let hoverRating = 0;
Expand All @@ -29,7 +31,7 @@
$: formField = formApi?.registerField(
field,
"number",
0,
defaultValue,
false,
validation,
formStep
Expand Down Expand Up @@ -72,9 +74,9 @@
? hoverRating >= i + 1
: fieldState?.value >= i + 1}
starId={i + 1}
on:mouseover={() => (hoverRating = i + 1)}
on:mouseleave={() => (hoverRating = null)}
on:click={() => fieldApi?.setValue(i + 1)}
on:mouseover={disabled ? null : () => (hoverRating = i + 1)}
on:mouseleave={disabled ? null : () => (hoverRating = null)}
on:click={disabled ? null : () => fieldApi?.setValue(i + 1)}
/>
{/each}
{#if !field}
Expand Down

0 comments on commit e8b609d

Please sign in to comment.