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gBAAgB;gCACzB,OAAO,IAAI,QAAQ,CAAC,WAAW;6BAC/B;4BAEA,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC;4BACrD,WAAW,CAAC,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CACpD,CACP,CAAC;qBACF;yBAAM;wBACN,OAAO,CACN,cACC,OAAO,EAAE;gCACR,YAAY,KAAK,WAAW,IAAI,QAAQ,CAAC,WAAW;6BACpD,IAEA,WAAW,CAAC,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CACpD,CACP,CAAC;qBACF;gBACF,CAAC,CAAC,CAAC;YACJ,CAAC;SACD,CACW,CACR,CACN,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,eAAe,IAAI,CAAC","sourcesContent":["import { focus } from '@dojo/framework/core/middleware/focus';\nimport { create, tsx } from '@dojo/framework/core/vdom';\nimport theme from '../middleware/theme';\nimport * as css from '../theme/default/rate.m.css';\nimport * as fixedCss from './rate.m.css';\nimport * as baseCss from '../common/styles/base.m.css';\nimport RadioGroup from '../radio-group';\nimport { createICacheMiddleware } from '@dojo/framework/core/middleware/icache';\nimport Icon from '../icon';\nimport { RenderResult } from '@dojo/framework/core/interfaces';\n\nexport interface RateProperties {\n\t/** Handler for when the value of the widget changes */\n\tonValue?(value: number): void;\n\t/* Number of icons to show, defaults to 5*/\n\tmax?: number;\n\t/* Initial value for this widget */\n\tinitialValue?: number;\n\t/* Controlled value for this widget */\n\tvalue?: number;\n\t/* The form name for this rate widget */\n\tname?: string;\n\t/* Flag to indicate if half stars should be used */\n\tallowHalf?: boolean;\n\t/* Flag to set the readonly state */\n\treadOnly?: boolean;\n}\n\nexport interface RateChildren {\n\t/* The label to be rendered form this rate widget */\n\tlabel?: RenderResult;\n\n\t/* The icon to be used, default is a star, this icon should be a font icon or an svg that accepts a `fill` to denote it's colour */\n\ticon?: RenderResult;\n}\n\ninterface RateIcache {\n\tvalue: number;\n\tvalueHovered: number;\n\tinitialValue: number;\n\tvalueFocused: string;\n\tfocused: boolean;\n}\n\nconst factory = create({ focus, theme, icache: createICacheMiddleware<RateIcache>() })\n\t.properties<RateProperties>()\n\t.children<RateChildren | undefined>();\n\nexport const Rate = factory(function Rate({\n\tproperties,\n\tid,\n\tchildren,\n\tmiddleware: { theme, icache }\n}) {\n\tconst idBase = `rate-${id}`;\n\tconst {\n\t\tonValue,\n\t\tmax = 5,\n\t\tinitialValue,\n\t\tallowHalf,\n\t\tname = idBase,\n\t\treadOnly,\n\t\ttheme: themeProp,\n\t\tclasses,\n\t\tvariant\n\t} = properties();\n\tlet { value } = properties();\n\tconst [{ label, icon } = { label: undefined, icon: undefined }] = children();\n\n\tconst themeCss = theme.classes(css);\n\tconst hoveredValue = icache.getOrSet('valueHovered', 0);\n\n\tif (value === undefined) {\n\t\tif (initialValue !== undefined) {\n\t\t\tconst previousInitialValue = icache.get('initialValue');\n\t\t\tif (initialValue !== previousInitialValue) {\n\t\t\t\ticache.set('initialValue', initialValue);\n\t\t\t\ticache.set('value', initialValue);\n\t\t\t}\n\t\t}\n\n\t\tvalue = icache.getOrSet('value', 0);\n\t}\n\n\tvalue = allowHalf ? Math.round(value * 2) / 2 : Math.round(value);\n\n\tconst options = [];\n\tfor (let i = 1; i <= max; i++) {\n\t\toptions.push({ value: `${i}` });\n\t}\n\n\tconst valueFocused = icache.getOrSet('valueFocused', '');\n\tconst containsFocus = icache.getOrSet('focused', false);\n\n\tfunction renderRadio(stringValue: string, checked: (checked?: boolean) => boolean) {\n\t\tconst numValue = parseFloat(stringValue);\n\t\tconst visiblyChecked = hoveredValue\n\t\t\t? numValue <= hoveredValue\n\t\t\t: !!value && numValue <= value;\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\tclasses={[\n\t\t\t\t\ttheme.variant(),\n\t\t\t\t\tfixedCss.labelFixed,\n\t\t\t\t\tthemeCss.icon,\n\t\t\t\t\tvisiblyChecked && themeCss.checked\n\t\t\t\t]}\n\t\t\t\tonmouseenter={() => {\n\t\t\t\t\t!readOnly && icache.set('valueHovered', numValue);\n\t\t\t\t}}\n\t\t\t\tonmouseleave={() => {\n\t\t\t\t\t!readOnly && icache.set('valueHovered', 0);\n\t\t\t\t}}\n\t\t\t\ttitle={stringValue}\n\t\t\t>\n\t\t\t\t<span classes={fixedCss.iconWrapperFixed}>\n\t\t\t\t\t{icon || (\n\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\tsize=\"medium\"\n\t\t\t\t\t\t\ttype=\"starIcon\"\n\t\t\t\t\t\t\ttheme={themeProp}\n\t\t\t\t\t\t\tvariant={variant}\n\t\t\t\t\t\t\tclasses={classes}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t</span>\n\t\t\t\t<input\n\t\t\t\t\tclasses={baseCss.visuallyHidden}\n\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\tchecked={checked()}\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={stringValue}\n\t\t\t\t\tonfocus={() => {\n\t\t\t\t\t\ticache.set('valueFocused', stringValue);\n\t\t\t\t\t\ticache.set('focused', true);\n\t\t\t\t\t}}\n\t\t\t\t\tonblur={() => {\n\t\t\t\t\t\ticache.set('focused', false);\n\t\t\t\t\t}}\n\t\t\t\t\tdisabled={readOnly}\n\t\t\t\t\tonchange={(event: Event) => {\n\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\tconst radio = event.target as HTMLInputElement;\n\t\t\t\t\t\tchecked(radio.checked);\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div classes={[themeCss.root, theme.variant(), containsFocus && themeCss.focused]}>\n\t\t\t<RadioGroup\n\t\t\t\tkey=\"radio-group\"\n\t\t\t\tname={name}\n\t\t\t\toptions={options}\n\t\t\t\tonValue={(value: string) => {\n\t\t\t\t\tif (!readOnly) {\n\t\t\t\t\t\tconst numberVal = parseFloat(value);\n\t\t\t\t\t\ticache.set('value', numberVal);\n\t\t\t\t\t\ticache.set('valueHovered', 0);\n\t\t\t\t\t\tonValue && onValue(numberVal);\n\t\t\t\t\t}\n\t\t\t\t}}\n\t\t\t\tvariant={variant}\n\t\t\t\ttheme={themeProp}\n\t\t\t\tclasses={classes}\n\t\t\t>\n\t\t\t\t{{\n\t\t\t\t\tlabel,\n\t\t\t\t\tradios: (name, radioGroup, options) => {\n\t\t\t\t\t\treturn options.map(({ value: stringValue }) => {\n\t\t\t\t\t\t\tif (allowHalf) {\n\t\t\t\t\t\t\t\tconst halfValue = `${parseFloat(stringValue) - 0.5}`;\n\t\t\t\t\t\t\t\tlet focused = false;\n\t\t\t\t\t\t\t\tif (valueFocused === halfValue || valueFocused === stringValue) {\n\t\t\t\t\t\t\t\t\tfocused = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\tclasses={[\n\t\t\t\t\t\t\t\t\t\t\tfixedCss.halfWrapperFixed,\n\t\t\t\t\t\t\t\t\t\t\tfocused && themeCss.focusedStar\n\t\t\t\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{renderRadio(halfValue, radioGroup(halfValue).checked)}\n\t\t\t\t\t\t\t\t\t\t{renderRadio(stringValue, radioGroup(stringValue).checked)}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\tclasses={[\n\t\t\t\t\t\t\t\t\t\t\tvalueFocused === stringValue && themeCss.focusedStar\n\t\t\t\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{renderRadio(stringValue, radioGroup(stringValue).checked)}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}}\n\t\t\t</RadioGroup>\n\t\t</div>\n\t);\n});\n\nexport default Rate;\n"]}