@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 4.33 kB
Source Map (JSON)
{"version":3,"file":"strength-meter.cjs","names":["createSlotComponent","strengthMeterStyle","percent","useStrengthMeter","styled"],"sources":["../../../../src/components/password-input/strength-meter.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { HTMLStyledProps } from \"../../core\"\nimport type { StrengthMeterStyle } from \"./strength-meter.style\"\nimport type { UseStrengthMeterProps } from \"./use-strength-meter\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { strengthMeterStyle } from \"./strength-meter.style\"\nimport { useStrengthMeter } from \"./use-strength-meter\"\n\ninterface IndicatorProps extends HTMLStyledProps {\n label?: ReactNode\n}\n\nexport interface StrengthMeterProps\n extends HTMLStyledProps,\n UseStrengthMeterProps {\n /**\n * If `true`, the password strength meter will display the label.\n *\n * @default true\n */\n withLabel?: boolean\n /**\n * The props of the password strength meter indicator.\n */\n getIndicatorProps?: (percent: number) => IndicatorProps\n}\n\nconst {\n PropsContext: StrengthMeterPropsContext,\n usePropsContext: useStrengthMeterPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<StrengthMeterProps, StrengthMeterStyle>(\n \"strength-meter\",\n strengthMeterStyle,\n)\n\nexport { StrengthMeterPropsContext, useStrengthMeterPropsContext }\n\nexport const StrengthMeter = withProvider<\"div\", StrengthMeterProps>(\n ({\n max = 4,\n value,\n withLabel = true,\n getIndicatorProps: getCustomIndicatorProps,\n ...rest\n }) => {\n const percent = (value / max) * 100\n\n const getDefaultIndicatorProps = (percent: number): IndicatorProps => {\n switch (true) {\n case percent < 33:\n return { label: \"Low\", _selected: { bg: \"red.500\" } }\n case percent < 66:\n return { label: \"Medium\", _selected: { bg: \"orange.500\" } }\n default:\n return { label: \"High\", _selected: { bg: \"green.500\" } }\n }\n }\n\n getCustomIndicatorProps ??= getDefaultIndicatorProps\n\n const { label, ...indicatorProps } = getCustomIndicatorProps(percent)\n\n const { getIndicatorProps, getRootProps } = useStrengthMeter({\n max,\n value,\n ...rest,\n })\n\n return (\n <styled.div {...getRootProps()}>\n <StrengthMeterIndicators>\n {Array.from({ length: max }).map((_, index) => (\n <StrengthMeterIndicator\n key={index}\n {...getIndicatorProps({ index, ...indicatorProps })}\n />\n ))}\n </StrengthMeterIndicators>\n\n {withLabel && label ? (\n <StrengthMeterLabel>{label}</StrengthMeterLabel>\n ) : null}\n </styled.div>\n )\n },\n \"root\",\n)()\n\ninterface StrengthMeterIndicatorsProps extends HTMLStyledProps {}\n\nconst StrengthMeterIndicators = withContext<\n \"div\",\n StrengthMeterIndicatorsProps\n>(\"div\", \"indicators\")()\n\ninterface StrengthMeterIndicatorProps extends HTMLStyledProps {}\n\nconst StrengthMeterIndicator = withContext<\"div\", StrengthMeterIndicatorProps>(\n \"div\",\n \"indicator\",\n)()\n\ninterface StrengthMeterLabelProps extends HTMLStyledProps<\"span\"> {}\n\nconst StrengthMeterLabel = withContext<\"span\", StrengthMeterLabelProps>(\n \"span\",\n \"label\",\n)()\n"],"mappings":";;;;;;;;;;;;AA6BA,MAAM,EACJ,cAAc,2BACd,iBAAiB,8BACjB,aACA,iBACEA,6CACF,kBACAC,gDACD;AAID,MAAa,gBAAgB,cAC1B,EACC,MAAM,GACN,OACA,YAAY,MACZ,mBAAmB,wBACnB,GAAG,WACC;CACJ,MAAM,UAAW,QAAQ,MAAO;CAEhC,MAAM,4BAA4B,cAAoC;AACpE,UAAQ,MAAR;GACE,KAAKC,YAAU,GACb,QAAO;IAAE,OAAO;IAAO,WAAW,EAAE,IAAI,WAAW;IAAE;GACvD,KAAKA,YAAU,GACb,QAAO;IAAE,OAAO;IAAU,WAAW,EAAE,IAAI,cAAc;IAAE;GAC7D,QACE,QAAO;IAAE,OAAO;IAAQ,WAAW,EAAE,IAAI,aAAa;IAAE;;;AAI9D,6BAA4B;CAE5B,MAAM,EAAE,MAAO,GAAG,mBAAmB,wBAAwB,QAAQ;CAErE,MAAM,EAAE,mBAAmB,iBAAiBC,4CAAiB;EAC3D;EACA;EACA,GAAG;EACJ,CAAC;AAEF,QACE,4CAACC,uBAAO;EAAI,GAAI,cAAc;aAC5B,2CAAC,qCACE,MAAM,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC,KAAK,GAAG,UACnC,2CAAC,0BAEC,GAAI,kBAAkB;GAAE;GAAO,GAAG;GAAgB,CAAC,IAD9C,MAEL,CACF,GACsB,EAEzB,aAAa,QACZ,2CAAC,gCAAoB,QAA2B,GAC9C;GACO;GAGjB,OACD,EAAE;AAIH,MAAM,0BAA0B,YAG9B,OAAO,aAAa,EAAE;AAIxB,MAAM,yBAAyB,YAC7B,OACA,YACD,EAAE;AAIH,MAAM,qBAAqB,YACzB,QACA,QACD,EAAE"}