UNPKG

@sjsf-lab/shadcn-extras-theme

Version:

The shadcn-svelte-extras based theme for svelte-jsonschema-form

37 lines (36 loc) 1.05 kB
import { Context } from 'runed'; export class StarRatingRootState { opts; constructor(opts) { this.opts = opts; this.setRating = this.setRating.bind(this); } setRating(star) { if (this.opts.disabled.current || this.opts.readonly.current) return; if (star > this.opts.stars.current || star < 0) { console.warn(`[star-rating] ${star} is not a valid rating`); return; } this.opts.value.current = star; } } export class StarRatingStarState { rootState; opts; constructor(rootState, opts) { this.rootState = rootState; this.opts = opts; this.setRating = this.setRating.bind(this); } setRating() { this.rootState.setRating(this.opts.star.current); } } const ctx = new Context('star-rating-root-state'); export function useStarRating(props) { return ctx.set(new StarRatingRootState(props)); } export function useStarRatingStar(props) { return new StarRatingStarState(ctx.get(), props); }