import { useMemo } from "react"; import SciteBadge from "Components/SciteBadge"; import { NumericSelect, SingleInput, Toggle , SettingsManager } from "Components/UserSettings"; const { Provider: SciteProvider, useSettings: useSciteSettings } = new SettingsManager<"sciteBadge">(); const EXAMPLE_DOI = "10.1126/science.1179052"; const LAYOUT_OPTIONS = [ { label: "Horizontal", value: "horizontal" }, { label: "Vertical", value: "vertical" } ]; const PLACEMENT_OPTIONS = [ { label: "Auto", value: "auto" }, { label: "Top", value: "top" }, { label: "Left", value: "left" }, { label: "Right", value: "right" }, { label: "Bottom", value: "bottom" } ]; function SciteWidget(){ const [ { layout, showLabels, showZero, small, tooltipPlacement, tooltipSlide }, setOpts ] = useSciteSettings(); const handlers = useMemo(() => { function toggleBool(op){ setOpts(prevState => ({ ...prevState, [op]: !prevState[op] })); } function updateSingleValue(op, val){ setOpts(prevState => ({ ...prevState, [op]: val })); } return { selectLayout: (val) => updateSingleValue("layout", val), toggleLabels: () => toggleBool("showLabels"), toggleZero: () => toggleBool("showZero"), toggleSmall: () => toggleBool("small"), selectTooltipPlacement: (val) => updateSingleValue("tooltipPlacement", val), updateTooltipSlide: (val) => updateSingleValue("tooltipSlide", val) }; }, [setOpts]); return <>
; } export { SciteProvider, SciteWidget, useSciteSettings };