@stokelp/ui 2.112.0 → 2.114.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat/ChatScoreBreakdown.cjs +1 -1
- package/dist/components/chat/ChatScoreBreakdown.cjs.map +1 -1
- package/dist/components/chat/ChatScoreBreakdown.js +13 -4
- package/dist/components/chat/ChatScoreBreakdown.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBadge.cjs +2 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBadge.cjs.map +1 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBadge.d.ts +9 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBadge.js +99 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBadge.js.map +1 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBreakdown.cjs +2 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBreakdown.cjs.map +1 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBreakdown.d.ts +47 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBreakdown.js +241 -0
- package/dist/components/supplier-rating-badge/SupplierRatingBreakdown.js.map +1 -0
- package/dist/components/supplier-rating-badge/index.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +16 -14
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/CheckCircleIcon.cjs +2 -0
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/CheckCircleIcon.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/CheckCircleIcon.js +25 -0
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/CheckCircleIcon.js.map +1 -0
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/XCircleIcon.cjs +2 -0
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/XCircleIcon.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/XCircleIcon.js +25 -0
- package/dist/node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/XCircleIcon.js.map +1 -0
- package/dist/ui.css +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../text/Text.cjs");let t=require("@stokelp/styled-system/jsx"),n=require("react/jsx-runtime");var r=1,i=[`origin`,`rawMaterialOrigin`,`temperature`,`cutting`,`cooking`,`treatment`,`label`,`packaging`,`grammageGsm`,`recycledPct`,`thicknessMicron`],a=[`temperature`,`cutting`,`cooking`],o=[`grammageGsm`,`recycledPct`,`thicknessMicron`],s={egal:{bg:`#E6F3D9`,color:`#3B6D11`},proche:{bg:`#F0F6DC`,color:`#5E8516`},eloigne:{bg:`#FDF0E0`,color:`#C2740C`},non_correspondant:{bg:`#FCEBEB`,color:`#A32D2D`}};function c(e){return e>=70?`#3B6D11`:e>=40?`#854F0B`:`#A32D2D`}function l(e){return e>=70?`#639922`:e>=40?`#BA7517`:`#E24B4A`}function u(e){return e?.level!=null}function d(e){return e?.matched!=null&&e?.total!=null}function f(e){return u(e)||d(e)}var p=({percent:d,detail:p,labels:m,typologyId:h})=>{let g=Number(h)===r||o.some(e=>p[e]?.level!=null),_=new Set(g?a:o),v=i.filter(e=>!_.has(e)),y=v.filter(e=>f(p[e])),b=v.filter(e=>!f(p[e])&&m.attributes[e]!=null);return(0,n.jsxs)(t.Box,{bg:`white`,borderRadius:`radius-8`,p:`space-16`,minW:`220px`,maxW:`240px`,css:{"& *":{fontFamily:`inherit`}},children:[(0,n.jsxs)(t.HStack,{justify:`space-between`,alignItems:`baseline`,mb:`space-8`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.md`,fontWeight:`bold`,children:m.title}),(0,n.jsxs)(e.Text,{as:`span`,fontSize:`body.lg`,fontWeight:`medium`,style:{color:c(d)},children:[Math.round(d),` %`]})]}),(0,n.jsx)(t.Box,{h:`1px`,bg:`grey.100`,mb:`space-8`}),y.length>0&&(0,n.jsxs)(t.VStack,{alignItems:`stretch`,gap:`space-4`,mb:`space-8`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`bold`,color:`grey.400`,children:m.compared}),y.map(r=>{let i=p[r];if(u(i)){let a=i.level,o=s[a];return(0,n.jsxs)(t.HStack,{alignItems:`center`,gap:`space-8`,justify:`space-between`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,color:`grey.500`,minW:`80px`,children:m.attributes[r]}),(0,n.jsx)(t.Box,{px:`space-
|
|
1
|
+
"use client";const e=require("../text/Text.cjs");let t=require("@stokelp/styled-system/jsx"),n=require("react/jsx-runtime");var r=1,i=[`origin`,`rawMaterialOrigin`,`temperature`,`cutting`,`cooking`,`treatment`,`label`,`packaging`,`grammageGsm`,`recycledPct`,`thicknessMicron`],a=[`temperature`,`cutting`,`cooking`],o=[`grammageGsm`,`recycledPct`,`thicknessMicron`],s={egal:{bg:`#E6F3D9`,color:`#3B6D11`},proche:{bg:`#F0F6DC`,color:`#5E8516`},eloigne:{bg:`#FDF0E0`,color:`#C2740C`},non_correspondant:{bg:`#FCEBEB`,color:`#A32D2D`}};function c(e){return e>=70?`#3B6D11`:e>=40?`#854F0B`:`#A32D2D`}function l(e){return e>=70?`#639922`:e>=40?`#BA7517`:`#E24B4A`}function u(e){return e?.level!=null}function d(e){return e?.matched!=null&&e?.total!=null}function f(e){return u(e)||d(e)}var p=({percent:d,detail:p,labels:m,typologyId:h})=>{let g=Number(h)===r||o.some(e=>p[e]?.level!=null),_=new Set(g?a:o),v=i.filter(e=>!_.has(e)),y=v.filter(e=>f(p[e])),b=v.filter(e=>!f(p[e])&&m.attributes[e]!=null);return(0,n.jsxs)(t.Box,{bg:`white`,borderRadius:`radius-8`,p:`space-16`,minW:`220px`,maxW:`240px`,css:{"& *":{fontFamily:`inherit`}},children:[(0,n.jsxs)(t.HStack,{justify:`space-between`,alignItems:`baseline`,mb:`space-8`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.md`,fontWeight:`bold`,children:m.title}),(0,n.jsxs)(e.Text,{as:`span`,fontSize:`body.lg`,fontWeight:`medium`,style:{color:c(d)},children:[Math.round(d),` %`]})]}),(0,n.jsx)(t.Box,{h:`1px`,bg:`grey.100`,mb:`space-8`}),y.length>0&&(0,n.jsxs)(t.VStack,{alignItems:`stretch`,gap:`space-4`,mb:`space-8`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`bold`,color:`grey.400`,children:m.compared}),y.map(r=>{let i=p[r];if(u(i)){let a=i.level,o=s[a];return(0,n.jsxs)(t.HStack,{h:`18px`,alignItems:`center`,gap:`space-8`,justify:`space-between`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,color:`grey.500`,minW:`80px`,children:m.attributes[r]}),(0,n.jsx)(t.Box,{display:`flex`,alignItems:`center`,justifyContent:`center`,h:`100%`,px:`space-6`,borderRadius:`full`,flexShrink:`0`,style:{backgroundColor:o.bg},children:(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`medium`,style:{color:o.color,whiteSpace:`nowrap`,lineHeight:1},children:m.levels?.[a]??a})})]},r)}let a=i.matched,o=i.total,c=o>0?a/o*100:0;return(0,n.jsxs)(t.HStack,{h:`18px`,alignItems:`center`,gap:`space-8`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,color:`grey.500`,minW:`80px`,children:m.attributes[r]}),(0,n.jsx)(t.Box,{flex:`1`,h:`3px`,bg:`grey.100`,borderRadius:`full`,overflow:`hidden`,children:(0,n.jsx)(t.Box,{h:`100%`,borderRadius:`full`,style:{width:`${c}%`,background:l(c)}})}),(0,n.jsxs)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`medium`,minW:`40px`,textAlign:`right`,style:{color:l(c),lineHeight:1},children:[a,`/`,o]})]},r)})]}),y.length>0&&b.length>0&&(0,n.jsx)(t.Box,{h:`1px`,bg:`grey.100`,mb:`space-8`}),b.length>0&&(0,n.jsxs)(t.VStack,{alignItems:`stretch`,gap:`space-4`,children:[(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`bold`,color:`grey.400`,children:m.notSpecified}),(0,n.jsx)(t.HStack,{flexWrap:`wrap`,gap:`space-4`,children:b.map(t=>(0,n.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,color:`grey.400`,border:`1px solid`,borderColor:`grey.100`,px:`space-8`,py:`2px`,borderRadius:`full`,children:m.attributes[t]},t))})]}),m.footer&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.Box,{h:`1px`,bg:`grey.100`,mt:`space-8`,mb:`space-8`}),(0,n.jsx)(e.Text,{as:`span`,fontSize:`9px`,color:`grey.300`,style:{lineHeight:1},children:m.footer})]})]})};exports.ChatScoreBreakdown=p;
|
|
2
2
|
//# sourceMappingURL=ChatScoreBreakdown.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatScoreBreakdown.cjs","names":[],"sources":["../../../src/components/chat/ChatScoreBreakdown.tsx"],"sourcesContent":["import { Box, HStack, VStack } from '@stokelp/styled-system/jsx'\nimport { Text } from '~/components'\n\nexport type ScoreSetAttributeKey =\n | 'origin'\n | 'rawMaterialOrigin'\n | 'temperature'\n | 'cutting'\n | 'cooking'\n | 'treatment'\n | 'label'\n | 'packaging'\n\nexport type ScoreNumericAttributeKey = 'grammageGsm' | 'recycledPct' | 'thicknessMicron'\n\nexport type ScoreAttributeKey = ScoreSetAttributeKey | ScoreNumericAttributeKey\n\n/** Proximity bucket for free numeric packaging specs: egal (equal) → non_correspondant (no match). */\nexport type ScoreLevel = 'egal' | 'proche' | 'eloigne' | 'non_correspondant'\n\nexport type ScoreAttributeDetail = {\n matched: number | null\n total: number | null\n level?: ScoreLevel | null\n}\n\nexport type ChatScoreBreakdownLabels = {\n title: string\n compared: string\n notSpecified: string\n attributes: Record<ScoreSetAttributeKey, string> & Partial<Record<ScoreNumericAttributeKey, string>>\n levels?: Record<ScoreLevel, string>\n footer?: string\n}\n\nexport type ChatScoreBreakdownProps = {\n percent: number\n detail: Record<string, ScoreAttributeDetail>\n labels: ChatScoreBreakdownLabels\n /** Typology id of the AO product (1 = packaging). When provided, drives which attribute family is shown; falls back to inferring from the numeric specs when absent. */\n typologyId?: number\n}\n\nconst PACKAGING_TYPOLOGY_ID = 1\n\nconst ATTRIBUTE_ORDER: ScoreAttributeKey[] = [\n 'origin',\n 'rawMaterialOrigin',\n 'temperature',\n 'cutting',\n 'cooking',\n 'treatment',\n 'label',\n 'packaging',\n 'grammageGsm',\n 'recycledPct',\n 'thicknessMicron',\n]\n\n// Attributes that only exist for food products; hidden for packaging products.\nconst FOOD_ONLY_KEYS: ScoreAttributeKey[] = ['temperature', 'cutting', 'cooking']\n// Free numeric specs that only exist for packaging products; hidden for food products.\nconst PACKAGING_ONLY_KEYS: ScoreNumericAttributeKey[] = ['grammageGsm', 'recycledPct', 'thicknessMicron']\n\nconst LEVEL_COLORS: Record<ScoreLevel, { bg: string; color: string }> = {\n egal: { bg: '#E6F3D9', color: '#3B6D11' },\n proche: { bg: '#F0F6DC', color: '#5E8516' },\n eloigne: { bg: '#FDF0E0', color: '#C2740C' },\n non_correspondant: { bg: '#FCEBEB', color: '#A32D2D' },\n}\n\nfunction getHeadlineColor(percent: number): string {\n if (percent >= 70) return '#3B6D11'\n if (percent >= 40) return '#854F0B'\n return '#A32D2D'\n}\n\nfunction getBarColor(ratioPercent: number): string {\n if (ratioPercent >= 70) return '#639922'\n if (ratioPercent >= 40) return '#BA7517'\n return '#E24B4A'\n}\n\nfunction hasLevel(detail?: ScoreAttributeDetail): boolean {\n return detail?.level != null\n}\n\nfunction isFraction(detail?: ScoreAttributeDetail): boolean {\n return detail?.matched != null && detail?.total != null\n}\n\nfunction isComparable(detail?: ScoreAttributeDetail): boolean {\n return hasLevel(detail) || isFraction(detail)\n}\n\nexport const ChatScoreBreakdown = ({ percent, detail, labels, typologyId }: ChatScoreBreakdownProps) => {\n // A packaging product hides food attributes (temperature/cutting/cooking) and shows the\n // numeric specs, and vice versa. Two independent signals mark a packaging product, combined\n // so neither can wrongly override the other: the AO product typology (authoritative, and the\n // only signal when no numeric spec is comparable), and the presence of a comparable numeric\n // spec (covers cases where the typology is absent or not sent as the expected value).\n const isPackaging =\n Number(typologyId) === PACKAGING_TYPOLOGY_ID || PACKAGING_ONLY_KEYS.some(key => detail[key]?.level != null)\n const hiddenKeys = new Set<ScoreAttributeKey>(isPackaging ? FOOD_ONLY_KEYS : PACKAGING_ONLY_KEYS)\n const visibleKeys = ATTRIBUTE_ORDER.filter(key => !hiddenKeys.has(key))\n\n const compared = visibleKeys.filter(key => isComparable(detail[key]))\n const notSpecified = visibleKeys.filter(key => !isComparable(detail[key]) && labels.attributes[key] != null)\n\n return (\n <Box\n bg=\"white\"\n borderRadius=\"radius-8\"\n p=\"space-16\"\n minW=\"220px\"\n maxW=\"240px\"\n css={{ '& *': { fontFamily: 'inherit' } }}\n >\n <HStack justify=\"space-between\" alignItems=\"baseline\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.md\" fontWeight=\"bold\">\n {labels.title}\n </Text>\n <Text as=\"span\" fontSize=\"body.lg\" fontWeight=\"medium\" style={{ color: getHeadlineColor(percent) }}>\n {Math.round(percent)} %\n </Text>\n </HStack>\n\n <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />\n\n {compared.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.compared}\n </Text>\n {compared.map(key => {\n const entry = detail[key]\n if (hasLevel(entry)) {\n const level = entry.level as ScoreLevel\n const colors = LEVEL_COLORS[level]\n return (\n <HStack key={key} alignItems=\"center\" gap=\"space-8\" justify=\"space-between\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box px=\"space-8\" py=\"2px\" borderRadius=\"full\" flexShrink=\"0\" style={{ backgroundColor: colors.bg }}>\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n style={{ color: colors.color, whiteSpace: 'nowrap' }}\n >\n {labels.levels?.[level] ?? level}\n </Text>\n </Box>\n </HStack>\n )\n }\n\n const matched = entry.matched as number\n const total = entry.total as number\n const ratioPercent = total > 0 ? (matched / total) * 100 : 0\n return (\n <HStack key={key} alignItems=\"center\" gap=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box flex=\"1\" h=\"3px\" bg=\"grey.100\" borderRadius=\"full\" overflow=\"hidden\">\n <Box\n h=\"100%\"\n borderRadius=\"full\"\n style={{ width: `${ratioPercent}%`, background: getBarColor(ratioPercent) }}\n />\n </Box>\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n minW=\"40px\"\n textAlign=\"right\"\n style={{ color: getBarColor(ratioPercent) }}\n >\n {matched}/{total}\n </Text>\n </HStack>\n )\n })}\n </VStack>\n )}\n\n {compared.length > 0 && notSpecified.length > 0 && <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />}\n\n {notSpecified.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.notSpecified}\n </Text>\n <HStack flexWrap=\"wrap\" gap=\"space-4\">\n {notSpecified.map(key => (\n <Text\n key={key}\n as=\"span\"\n fontSize=\"body.sm\"\n color=\"grey.400\"\n border=\"1px solid\"\n borderColor=\"grey.100\"\n px=\"space-8\"\n py=\"2px\"\n borderRadius=\"full\"\n >\n {labels.attributes[key]}\n </Text>\n ))}\n </HStack>\n </VStack>\n )}\n\n {labels.footer && (\n <>\n <Box h=\"1px\" bg=\"grey.100\" mt=\"space-8\" mb=\"space-8\" />\n <Text as=\"span\" fontSize=\"9px\" color=\"grey.300\" style={{ lineHeight: 1 }}>\n {labels.footer}\n </Text>\n </>\n )}\n </Box>\n )\n}\n"],"mappings":"4HA2CA,IAAM,EAAwB,EAExB,EAAuC,CAC3C,SACA,oBACA,cACA,UACA,UACA,YACA,QACA,YACA,cACA,cACA,iBACF,EAGM,EAAsC,CAAC,cAAe,UAAW,SAAS,EAE1E,EAAkD,CAAC,cAAe,cAAe,iBAAiB,EAElG,EAAkE,CACtE,KAAM,CAAE,GAAI,UAAW,MAAO,SAAU,EACxC,OAAQ,CAAE,GAAI,UAAW,MAAO,SAAU,EAC1C,QAAS,CAAE,GAAI,UAAW,MAAO,SAAU,EAC3C,kBAAmB,CAAE,GAAI,UAAW,MAAO,SAAU,CACvD,EAEA,SAAS,EAAiB,EAAyB,CAGjD,OAFI,GAAW,GAAW,UACtB,GAAW,GAAW,UACnB,SACT,CAEA,SAAS,EAAY,EAA8B,CAGjD,OAFI,GAAgB,GAAW,UAC3B,GAAgB,GAAW,UACxB,SACT,CAEA,SAAS,EAAS,EAAwC,CACxD,OAAO,GAAQ,OAAS,IAC1B,CAEA,SAAS,EAAW,EAAwC,CAC1D,OAAO,GAAQ,SAAW,MAAQ,GAAQ,OAAS,IACrD,CAEA,SAAS,EAAa,EAAwC,CAC5D,OAAO,EAAS,CAAM,GAAK,EAAW,CAAM,CAC9C,CAEA,IAAa,GAAsB,CAAE,UAAS,SAAQ,SAAQ,gBAA0C,CAMtG,IAAM,EACJ,OAAO,CAAU,IAAM,GAAyB,EAAoB,KAA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AAA,KAAC,EAAA,IAAD,CAAK,EAAE,MAAM,GAAG,WAAW,GAAG,SAAW,CAAA,EAE3F,EAAa,OAAS,IACrB,EAAA,EAAA,MAAC,EAAA,OAAD,CAAQ,WAAW,UAAU,IAAI,mBAAjC,EACE,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,GAAG,OAAO,SAAS,UAAU,WAAW,OAAO,MAAM,oBACxD,EAAO,YACJ,CAAA,GACN,EAAA,EAAA,KAAC,EAAA,OAAD,CAAQ,SAAS,OAAO,IAAI,mBACzB,EAAa,IAAI,IAChB,EAAA,EAAA,KAAC,EAAA,KAAD,CAEE,GAAG,OACH,SAAS,UACT,MAAM,WACN,OAAO,YACP,YAAY,WACZ,GAAG,UACH,GAAG,MACH,aAAa,gBAEZ,EAAO,WAAW,EACf,EAXC,CAWD,CACP,CACK,CAAA,CACF,IAGT,EAAO,SACN,EAAA,EAAA,MAAA,EAAA,SAAA,CAAA,SAAA,EACE,EAAA,EAAA,KAAC,EAAA,IAAD,CAAK,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,SAAW,CAAA,GACtD,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,GAAG,OAAO,SAAS,MAAM,MAAM,WAAW,MAAO,CAAE,WAAY,CAAE,WACpE,EAAO,MACJ,CAAA,CACN,CAAA,CAAA,CAED,GAET"}
|
|
1
|
+
{"version":3,"file":"ChatScoreBreakdown.cjs","names":[],"sources":["../../../src/components/chat/ChatScoreBreakdown.tsx"],"sourcesContent":["import { Box, HStack, VStack } from '@stokelp/styled-system/jsx'\nimport { Text } from '~/components'\n\nexport type ScoreSetAttributeKey =\n | 'origin'\n | 'rawMaterialOrigin'\n | 'temperature'\n | 'cutting'\n | 'cooking'\n | 'treatment'\n | 'label'\n | 'packaging'\n\nexport type ScoreNumericAttributeKey = 'grammageGsm' | 'recycledPct' | 'thicknessMicron'\n\nexport type ScoreAttributeKey = ScoreSetAttributeKey | ScoreNumericAttributeKey\n\n/** Proximity bucket for free numeric packaging specs: egal (equal) → non_correspondant (no match). */\nexport type ScoreLevel = 'egal' | 'proche' | 'eloigne' | 'non_correspondant'\n\nexport type ScoreAttributeDetail = {\n matched: number | null\n total: number | null\n level?: ScoreLevel | null\n}\n\nexport type ChatScoreBreakdownLabels = {\n title: string\n compared: string\n notSpecified: string\n attributes: Record<ScoreSetAttributeKey, string> & Partial<Record<ScoreNumericAttributeKey, string>>\n levels?: Record<ScoreLevel, string>\n footer?: string\n}\n\nexport type ChatScoreBreakdownProps = {\n percent: number\n detail: Record<string, ScoreAttributeDetail>\n labels: ChatScoreBreakdownLabels\n /** Typology id of the AO product (1 = packaging). When provided, drives which attribute family is shown; falls back to inferring from the numeric specs when absent. */\n typologyId?: number\n}\n\nconst PACKAGING_TYPOLOGY_ID = 1\n\nconst ATTRIBUTE_ORDER: ScoreAttributeKey[] = [\n 'origin',\n 'rawMaterialOrigin',\n 'temperature',\n 'cutting',\n 'cooking',\n 'treatment',\n 'label',\n 'packaging',\n 'grammageGsm',\n 'recycledPct',\n 'thicknessMicron',\n]\n\n// Attributes that only exist for food products; hidden for packaging products.\nconst FOOD_ONLY_KEYS: ScoreAttributeKey[] = ['temperature', 'cutting', 'cooking']\n// Free numeric specs that only exist for packaging products; hidden for food products.\nconst PACKAGING_ONLY_KEYS: ScoreNumericAttributeKey[] = ['grammageGsm', 'recycledPct', 'thicknessMicron']\n\nconst LEVEL_COLORS: Record<ScoreLevel, { bg: string; color: string }> = {\n egal: { bg: '#E6F3D9', color: '#3B6D11' },\n proche: { bg: '#F0F6DC', color: '#5E8516' },\n eloigne: { bg: '#FDF0E0', color: '#C2740C' },\n non_correspondant: { bg: '#FCEBEB', color: '#A32D2D' },\n}\n\nfunction getHeadlineColor(percent: number): string {\n if (percent >= 70) return '#3B6D11'\n if (percent >= 40) return '#854F0B'\n return '#A32D2D'\n}\n\nfunction getBarColor(ratioPercent: number): string {\n if (ratioPercent >= 70) return '#639922'\n if (ratioPercent >= 40) return '#BA7517'\n return '#E24B4A'\n}\n\nfunction hasLevel(detail?: ScoreAttributeDetail): boolean {\n return detail?.level != null\n}\n\nfunction isFraction(detail?: ScoreAttributeDetail): boolean {\n return detail?.matched != null && detail?.total != null\n}\n\nfunction isComparable(detail?: ScoreAttributeDetail): boolean {\n return hasLevel(detail) || isFraction(detail)\n}\n\nexport const ChatScoreBreakdown = ({ percent, detail, labels, typologyId }: ChatScoreBreakdownProps) => {\n // A packaging product hides food attributes (temperature/cutting/cooking) and shows the\n // numeric specs, and vice versa. Two independent signals mark a packaging product, combined\n // so neither can wrongly override the other: the AO product typology (authoritative, and the\n // only signal when no numeric spec is comparable), and the presence of a comparable numeric\n // spec (covers cases where the typology is absent or not sent as the expected value).\n const isPackaging =\n Number(typologyId) === PACKAGING_TYPOLOGY_ID || PACKAGING_ONLY_KEYS.some(key => detail[key]?.level != null)\n const hiddenKeys = new Set<ScoreAttributeKey>(isPackaging ? FOOD_ONLY_KEYS : PACKAGING_ONLY_KEYS)\n const visibleKeys = ATTRIBUTE_ORDER.filter(key => !hiddenKeys.has(key))\n\n const compared = visibleKeys.filter(key => isComparable(detail[key]))\n const notSpecified = visibleKeys.filter(key => !isComparable(detail[key]) && labels.attributes[key] != null)\n\n return (\n <Box\n bg=\"white\"\n borderRadius=\"radius-8\"\n p=\"space-16\"\n minW=\"220px\"\n maxW=\"240px\"\n css={{ '& *': { fontFamily: 'inherit' } }}\n >\n <HStack justify=\"space-between\" alignItems=\"baseline\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.md\" fontWeight=\"bold\">\n {labels.title}\n </Text>\n <Text as=\"span\" fontSize=\"body.lg\" fontWeight=\"medium\" style={{ color: getHeadlineColor(percent) }}>\n {Math.round(percent)} %\n </Text>\n </HStack>\n\n <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />\n\n {compared.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.compared}\n </Text>\n {compared.map(key => {\n const entry = detail[key]\n if (hasLevel(entry)) {\n const level = entry.level as ScoreLevel\n const colors = LEVEL_COLORS[level]\n return (\n <HStack key={key} h=\"18px\" alignItems=\"center\" gap=\"space-8\" justify=\"space-between\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box\n display=\"flex\"\n alignItems=\"center\"\n justifyContent=\"center\"\n h=\"100%\"\n px=\"space-6\"\n borderRadius=\"full\"\n flexShrink=\"0\"\n style={{ backgroundColor: colors.bg }}\n >\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n style={{ color: colors.color, whiteSpace: 'nowrap', lineHeight: 1 }}\n >\n {labels.levels?.[level] ?? level}\n </Text>\n </Box>\n </HStack>\n )\n }\n\n const matched = entry.matched as number\n const total = entry.total as number\n const ratioPercent = total > 0 ? (matched / total) * 100 : 0\n return (\n <HStack key={key} h=\"18px\" alignItems=\"center\" gap=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box flex=\"1\" h=\"3px\" bg=\"grey.100\" borderRadius=\"full\" overflow=\"hidden\">\n <Box\n h=\"100%\"\n borderRadius=\"full\"\n style={{ width: `${ratioPercent}%`, background: getBarColor(ratioPercent) }}\n />\n </Box>\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n minW=\"40px\"\n textAlign=\"right\"\n style={{ color: getBarColor(ratioPercent), lineHeight: 1 }}\n >\n {matched}/{total}\n </Text>\n </HStack>\n )\n })}\n </VStack>\n )}\n\n {compared.length > 0 && notSpecified.length > 0 && <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />}\n\n {notSpecified.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.notSpecified}\n </Text>\n <HStack flexWrap=\"wrap\" gap=\"space-4\">\n {notSpecified.map(key => (\n <Text\n key={key}\n as=\"span\"\n fontSize=\"body.sm\"\n color=\"grey.400\"\n border=\"1px solid\"\n borderColor=\"grey.100\"\n px=\"space-8\"\n py=\"2px\"\n borderRadius=\"full\"\n >\n {labels.attributes[key]}\n </Text>\n ))}\n </HStack>\n </VStack>\n )}\n\n {labels.footer && (\n <>\n <Box h=\"1px\" bg=\"grey.100\" mt=\"space-8\" mb=\"space-8\" />\n <Text as=\"span\" fontSize=\"9px\" color=\"grey.300\" style={{ lineHeight: 1 }}>\n {labels.footer}\n </Text>\n </>\n )}\n </Box>\n )\n}\n"],"mappings":"4HA2CA,IAAM,EAAwB,EAExB,EAAuC,CAC3C,SACA,oBACA,cACA,UACA,UACA,YACA,QACA,YACA,cACA,cACA,iBACF,EAGM,EAAsC,CAAC,cAAe,UAAW,SAAS,EAE1E,EAAkD,CAAC,cAAe,cAAe,iBAAiB,EAElG,EAAkE,CACtE,KAAM,CAAE,GAAI,UAAW,MAAO,SAAU,EACxC,OAAQ,CAAE,GAAI,UAAW,MAAO,SAAU,EAC1C,QAAS,CAAE,GAAI,UAAW,MAAO,SAAU,EAC3C,kBAAmB,CAAE,GAAI,UAAW,MAAO,SAAU,CACvD,EAEA,SAAS,EAAiB,EAAyB,CAGjD,OAFI,GAAW,GAAW,UACtB,GAAW,GAAW,UACnB,SACT,CAEA,SAAS,EAAY,EAA8B,CAGjD,OAFI,GAAgB,GAAW,UAC3B,GAAgB,GAAW,UACxB,SACT,CAEA,SAAS,EAAS,EAAwC,CACxD,OAAO,GAAQ,OAAS,IAC1B,CAEA,SAAS,EAAW,EAAwC,CAC1D,OAAO,GAAQ,SAAW,MAAQ,GAAQ,OAAS,IACrD,CAEA,SAAS,EAAa,EAAwC,CAC5D,OAAO,EAAS,CAAM,GAAK,EAAW,CAAM,CAC9C,CAEA,IAAa,GAAsB,CAAE,UAA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,CAAE,MAAO,EAAY,CAAY,EAAG,WAAY,CAAE,WAN3D,CAQG,EAAQ,IAAE,CACP,GACA,GArBK,CAqBL,CAEZ,CAAC,CACK,IAGT,EAAS,OAAS,GAAK,EAAa,OAAS,IAAK,EAAA,EAAA,KAAC,EAAA,IAAD,CAAK,EAAE,MAAM,GAAG,WAAW,GAAG,SAAW,CAAA,EAE3F,EAAa,OAAS,IACrB,EAAA,EAAA,MAAC,EAAA,OAAD,CAAQ,WAAW,UAAU,IAAI,mBAAjC,EACE,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,GAAG,OAAO,SAAS,UAAU,WAAW,OAAO,MAAM,oBACxD,EAAO,YACJ,CAAA,GACN,EAAA,EAAA,KAAC,EAAA,OAAD,CAAQ,SAAS,OAAO,IAAI,mBACzB,EAAa,IAAI,IAChB,EAAA,EAAA,KAAC,EAAA,KAAD,CAEE,GAAG,OACH,SAAS,UACT,MAAM,WACN,OAAO,YACP,YAAY,WACZ,GAAG,UACH,GAAG,MACH,aAAa,gBAEZ,EAAO,WAAW,EACf,EAXC,CAWD,CACP,CACK,CAAA,CACF,IAGT,EAAO,SACN,EAAA,EAAA,MAAA,EAAA,SAAA,CAAA,SAAA,EACE,EAAA,EAAA,KAAC,EAAA,IAAD,CAAK,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,SAAW,CAAA,GACtD,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,GAAG,OAAO,SAAS,MAAM,MAAM,WAAW,MAAO,CAAE,WAAY,CAAE,WACpE,EAAO,MACJ,CAAA,CACN,CAAA,CAAA,CAED,GAET"}
|
|
@@ -103,6 +103,7 @@ var _ = ({ percent: h, detail: _, labels: v, typologyId: y }) => {
|
|
|
103
103
|
if (m(i)) {
|
|
104
104
|
let s = i.level, c = d[s];
|
|
105
105
|
return /* @__PURE__ */ o(n, {
|
|
106
|
+
h: "18px",
|
|
106
107
|
alignItems: "center",
|
|
107
108
|
gap: "space-8",
|
|
108
109
|
justify: "space-between",
|
|
@@ -113,8 +114,11 @@ var _ = ({ percent: h, detail: _, labels: v, typologyId: y }) => {
|
|
|
113
114
|
minW: "80px",
|
|
114
115
|
children: v.attributes[r]
|
|
115
116
|
}), /* @__PURE__ */ a(t, {
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
display: "flex",
|
|
118
|
+
alignItems: "center",
|
|
119
|
+
justifyContent: "center",
|
|
120
|
+
h: "100%",
|
|
121
|
+
px: "space-6",
|
|
118
122
|
borderRadius: "full",
|
|
119
123
|
flexShrink: "0",
|
|
120
124
|
style: { backgroundColor: c.bg },
|
|
@@ -124,7 +128,8 @@ var _ = ({ percent: h, detail: _, labels: v, typologyId: y }) => {
|
|
|
124
128
|
fontWeight: "medium",
|
|
125
129
|
style: {
|
|
126
130
|
color: c.color,
|
|
127
|
-
whiteSpace: "nowrap"
|
|
131
|
+
whiteSpace: "nowrap",
|
|
132
|
+
lineHeight: 1
|
|
128
133
|
},
|
|
129
134
|
children: v.levels?.[s] ?? s
|
|
130
135
|
})
|
|
@@ -133,6 +138,7 @@ var _ = ({ percent: h, detail: _, labels: v, typologyId: y }) => {
|
|
|
133
138
|
}
|
|
134
139
|
let s = i.matched, c = i.total, l = c > 0 ? s / c * 100 : 0;
|
|
135
140
|
return /* @__PURE__ */ o(n, {
|
|
141
|
+
h: "18px",
|
|
136
142
|
alignItems: "center",
|
|
137
143
|
gap: "space-8",
|
|
138
144
|
children: [
|
|
@@ -164,7 +170,10 @@ var _ = ({ percent: h, detail: _, labels: v, typologyId: y }) => {
|
|
|
164
170
|
fontWeight: "medium",
|
|
165
171
|
minW: "40px",
|
|
166
172
|
textAlign: "right",
|
|
167
|
-
style: {
|
|
173
|
+
style: {
|
|
174
|
+
color: p(l),
|
|
175
|
+
lineHeight: 1
|
|
176
|
+
},
|
|
168
177
|
children: [
|
|
169
178
|
s,
|
|
170
179
|
"/",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatScoreBreakdown.js","names":[],"sources":["../../../src/components/chat/ChatScoreBreakdown.tsx"],"sourcesContent":["import { Box, HStack, VStack } from '@stokelp/styled-system/jsx'\nimport { Text } from '~/components'\n\nexport type ScoreSetAttributeKey =\n | 'origin'\n | 'rawMaterialOrigin'\n | 'temperature'\n | 'cutting'\n | 'cooking'\n | 'treatment'\n | 'label'\n | 'packaging'\n\nexport type ScoreNumericAttributeKey = 'grammageGsm' | 'recycledPct' | 'thicknessMicron'\n\nexport type ScoreAttributeKey = ScoreSetAttributeKey | ScoreNumericAttributeKey\n\n/** Proximity bucket for free numeric packaging specs: egal (equal) → non_correspondant (no match). */\nexport type ScoreLevel = 'egal' | 'proche' | 'eloigne' | 'non_correspondant'\n\nexport type ScoreAttributeDetail = {\n matched: number | null\n total: number | null\n level?: ScoreLevel | null\n}\n\nexport type ChatScoreBreakdownLabels = {\n title: string\n compared: string\n notSpecified: string\n attributes: Record<ScoreSetAttributeKey, string> & Partial<Record<ScoreNumericAttributeKey, string>>\n levels?: Record<ScoreLevel, string>\n footer?: string\n}\n\nexport type ChatScoreBreakdownProps = {\n percent: number\n detail: Record<string, ScoreAttributeDetail>\n labels: ChatScoreBreakdownLabels\n /** Typology id of the AO product (1 = packaging). When provided, drives which attribute family is shown; falls back to inferring from the numeric specs when absent. */\n typologyId?: number\n}\n\nconst PACKAGING_TYPOLOGY_ID = 1\n\nconst ATTRIBUTE_ORDER: ScoreAttributeKey[] = [\n 'origin',\n 'rawMaterialOrigin',\n 'temperature',\n 'cutting',\n 'cooking',\n 'treatment',\n 'label',\n 'packaging',\n 'grammageGsm',\n 'recycledPct',\n 'thicknessMicron',\n]\n\n// Attributes that only exist for food products; hidden for packaging products.\nconst FOOD_ONLY_KEYS: ScoreAttributeKey[] = ['temperature', 'cutting', 'cooking']\n// Free numeric specs that only exist for packaging products; hidden for food products.\nconst PACKAGING_ONLY_KEYS: ScoreNumericAttributeKey[] = ['grammageGsm', 'recycledPct', 'thicknessMicron']\n\nconst LEVEL_COLORS: Record<ScoreLevel, { bg: string; color: string }> = {\n egal: { bg: '#E6F3D9', color: '#3B6D11' },\n proche: { bg: '#F0F6DC', color: '#5E8516' },\n eloigne: { bg: '#FDF0E0', color: '#C2740C' },\n non_correspondant: { bg: '#FCEBEB', color: '#A32D2D' },\n}\n\nfunction getHeadlineColor(percent: number): string {\n if (percent >= 70) return '#3B6D11'\n if (percent >= 40) return '#854F0B'\n return '#A32D2D'\n}\n\nfunction getBarColor(ratioPercent: number): string {\n if (ratioPercent >= 70) return '#639922'\n if (ratioPercent >= 40) return '#BA7517'\n return '#E24B4A'\n}\n\nfunction hasLevel(detail?: ScoreAttributeDetail): boolean {\n return detail?.level != null\n}\n\nfunction isFraction(detail?: ScoreAttributeDetail): boolean {\n return detail?.matched != null && detail?.total != null\n}\n\nfunction isComparable(detail?: ScoreAttributeDetail): boolean {\n return hasLevel(detail) || isFraction(detail)\n}\n\nexport const ChatScoreBreakdown = ({ percent, detail, labels, typologyId }: ChatScoreBreakdownProps) => {\n // A packaging product hides food attributes (temperature/cutting/cooking) and shows the\n // numeric specs, and vice versa. Two independent signals mark a packaging product, combined\n // so neither can wrongly override the other: the AO product typology (authoritative, and the\n // only signal when no numeric spec is comparable), and the presence of a comparable numeric\n // spec (covers cases where the typology is absent or not sent as the expected value).\n const isPackaging =\n Number(typologyId) === PACKAGING_TYPOLOGY_ID || PACKAGING_ONLY_KEYS.some(key => detail[key]?.level != null)\n const hiddenKeys = new Set<ScoreAttributeKey>(isPackaging ? FOOD_ONLY_KEYS : PACKAGING_ONLY_KEYS)\n const visibleKeys = ATTRIBUTE_ORDER.filter(key => !hiddenKeys.has(key))\n\n const compared = visibleKeys.filter(key => isComparable(detail[key]))\n const notSpecified = visibleKeys.filter(key => !isComparable(detail[key]) && labels.attributes[key] != null)\n\n return (\n <Box\n bg=\"white\"\n borderRadius=\"radius-8\"\n p=\"space-16\"\n minW=\"220px\"\n maxW=\"240px\"\n css={{ '& *': { fontFamily: 'inherit' } }}\n >\n <HStack justify=\"space-between\" alignItems=\"baseline\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.md\" fontWeight=\"bold\">\n {labels.title}\n </Text>\n <Text as=\"span\" fontSize=\"body.lg\" fontWeight=\"medium\" style={{ color: getHeadlineColor(percent) }}>\n {Math.round(percent)} %\n </Text>\n </HStack>\n\n <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />\n\n {compared.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.compared}\n </Text>\n {compared.map(key => {\n const entry = detail[key]\n if (hasLevel(entry)) {\n const level = entry.level as ScoreLevel\n const colors = LEVEL_COLORS[level]\n return (\n <HStack key={key} alignItems=\"center\" gap=\"space-8\" justify=\"space-between\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box px=\"space-8\" py=\"2px\" borderRadius=\"full\" flexShrink=\"0\" style={{ backgroundColor: colors.bg }}>\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n style={{ color: colors.color, whiteSpace: 'nowrap' }}\n >\n {labels.levels?.[level] ?? level}\n </Text>\n </Box>\n </HStack>\n )\n }\n\n const matched = entry.matched as number\n const total = entry.total as number\n const ratioPercent = total > 0 ? (matched / total) * 100 : 0\n return (\n <HStack key={key} alignItems=\"center\" gap=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box flex=\"1\" h=\"3px\" bg=\"grey.100\" borderRadius=\"full\" overflow=\"hidden\">\n <Box\n h=\"100%\"\n borderRadius=\"full\"\n style={{ width: `${ratioPercent}%`, background: getBarColor(ratioPercent) }}\n />\n </Box>\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n minW=\"40px\"\n textAlign=\"right\"\n style={{ color: getBarColor(ratioPercent) }}\n >\n {matched}/{total}\n </Text>\n </HStack>\n )\n })}\n </VStack>\n )}\n\n {compared.length > 0 && notSpecified.length > 0 && <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />}\n\n {notSpecified.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.notSpecified}\n </Text>\n <HStack flexWrap=\"wrap\" gap=\"space-4\">\n {notSpecified.map(key => (\n <Text\n key={key}\n as=\"span\"\n fontSize=\"body.sm\"\n color=\"grey.400\"\n border=\"1px solid\"\n borderColor=\"grey.100\"\n px=\"space-8\"\n py=\"2px\"\n borderRadius=\"full\"\n >\n {labels.attributes[key]}\n </Text>\n ))}\n </HStack>\n </VStack>\n )}\n\n {labels.footer && (\n <>\n <Box h=\"1px\" bg=\"grey.100\" mt=\"space-8\" mb=\"space-8\" />\n <Text as=\"span\" fontSize=\"9px\" color=\"grey.300\" style={{ lineHeight: 1 }}>\n {labels.footer}\n </Text>\n </>\n )}\n </Box>\n )\n}\n"],"mappings":";;;;;AA2CA,IAAM,IAAwB,GAExB,IAAuC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAGM,IAAsC;CAAC;CAAe;CAAW;AAAS,GAE1E,IAAkD;CAAC;CAAe;CAAe;AAAiB,GAElG,IAAkE;CACtE,MAAM;EAAE,IAAI;EAAW,OAAO;CAAU;CACxC,QAAQ;EAAE,IAAI;EAAW,OAAO;CAAU;CAC1C,SAAS;EAAE,IAAI;EAAW,OAAO;CAAU;CAC3C,mBAAmB;EAAE,IAAI;EAAW,OAAO;CAAU;AACvD;AAEA,SAAS,EAAiB,GAAyB;CAGjD,OAFI,KAAW,KAAW,YACtB,KAAW,KAAW,YACnB;AACT;AAEA,SAAS,EAAY,GAA8B;CAGjD,OAFI,KAAgB,KAAW,YAC3B,KAAgB,KAAW,YAC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CAAC,CACK;;GAGT,EAAS,SAAS,KAAK,EAAa,SAAS,KAAK,kBAAC,GAAD;IAAK,GAAE;IAAM,IAAG;IAAW,IAAG;GAAW,CAAA;GAE3F,EAAa,SAAS,KACrB,kBAAC,GAAD;IAAQ,YAAW;IAAU,KAAI;cAAjC,CACE,kBAAC,GAAD;KAAM,IAAG;KAAO,UAAS;KAAU,YAAW;KAAO,OAAM;eACxD,EAAO;IACJ,CAAA,GACN,kBAAC,GAAD;KAAQ,UAAS;KAAO,KAAI;eACzB,EAAa,KAAI,MAChB,kBAAC,GAAD;MAEE,IAAG;MACH,UAAS;MACT,OAAM;MACN,QAAO;MACP,aAAY;MACZ,IAAG;MACH,IAAG;MACH,cAAa;gBAEZ,EAAO,WAAW;KACf,GAXC,CAWD,CACP;IACK,CAAA,CACF;;GAGT,EAAO,UACN,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD;IAAK,GAAE;IAAM,IAAG;IAAW,IAAG;IAAU,IAAG;GAAW,CAAA,GACtD,kBAAC,GAAD;IAAM,IAAG;IAAO,UAAS;IAAM,OAAM;IAAW,OAAO,EAAE,YAAY,EAAE;cACpE,EAAO;GACJ,CAAA,CACN,EAAA,CAAA;EAED;;AAET"}
|
|
1
|
+
{"version":3,"file":"ChatScoreBreakdown.js","names":[],"sources":["../../../src/components/chat/ChatScoreBreakdown.tsx"],"sourcesContent":["import { Box, HStack, VStack } from '@stokelp/styled-system/jsx'\nimport { Text } from '~/components'\n\nexport type ScoreSetAttributeKey =\n | 'origin'\n | 'rawMaterialOrigin'\n | 'temperature'\n | 'cutting'\n | 'cooking'\n | 'treatment'\n | 'label'\n | 'packaging'\n\nexport type ScoreNumericAttributeKey = 'grammageGsm' | 'recycledPct' | 'thicknessMicron'\n\nexport type ScoreAttributeKey = ScoreSetAttributeKey | ScoreNumericAttributeKey\n\n/** Proximity bucket for free numeric packaging specs: egal (equal) → non_correspondant (no match). */\nexport type ScoreLevel = 'egal' | 'proche' | 'eloigne' | 'non_correspondant'\n\nexport type ScoreAttributeDetail = {\n matched: number | null\n total: number | null\n level?: ScoreLevel | null\n}\n\nexport type ChatScoreBreakdownLabels = {\n title: string\n compared: string\n notSpecified: string\n attributes: Record<ScoreSetAttributeKey, string> & Partial<Record<ScoreNumericAttributeKey, string>>\n levels?: Record<ScoreLevel, string>\n footer?: string\n}\n\nexport type ChatScoreBreakdownProps = {\n percent: number\n detail: Record<string, ScoreAttributeDetail>\n labels: ChatScoreBreakdownLabels\n /** Typology id of the AO product (1 = packaging). When provided, drives which attribute family is shown; falls back to inferring from the numeric specs when absent. */\n typologyId?: number\n}\n\nconst PACKAGING_TYPOLOGY_ID = 1\n\nconst ATTRIBUTE_ORDER: ScoreAttributeKey[] = [\n 'origin',\n 'rawMaterialOrigin',\n 'temperature',\n 'cutting',\n 'cooking',\n 'treatment',\n 'label',\n 'packaging',\n 'grammageGsm',\n 'recycledPct',\n 'thicknessMicron',\n]\n\n// Attributes that only exist for food products; hidden for packaging products.\nconst FOOD_ONLY_KEYS: ScoreAttributeKey[] = ['temperature', 'cutting', 'cooking']\n// Free numeric specs that only exist for packaging products; hidden for food products.\nconst PACKAGING_ONLY_KEYS: ScoreNumericAttributeKey[] = ['grammageGsm', 'recycledPct', 'thicknessMicron']\n\nconst LEVEL_COLORS: Record<ScoreLevel, { bg: string; color: string }> = {\n egal: { bg: '#E6F3D9', color: '#3B6D11' },\n proche: { bg: '#F0F6DC', color: '#5E8516' },\n eloigne: { bg: '#FDF0E0', color: '#C2740C' },\n non_correspondant: { bg: '#FCEBEB', color: '#A32D2D' },\n}\n\nfunction getHeadlineColor(percent: number): string {\n if (percent >= 70) return '#3B6D11'\n if (percent >= 40) return '#854F0B'\n return '#A32D2D'\n}\n\nfunction getBarColor(ratioPercent: number): string {\n if (ratioPercent >= 70) return '#639922'\n if (ratioPercent >= 40) return '#BA7517'\n return '#E24B4A'\n}\n\nfunction hasLevel(detail?: ScoreAttributeDetail): boolean {\n return detail?.level != null\n}\n\nfunction isFraction(detail?: ScoreAttributeDetail): boolean {\n return detail?.matched != null && detail?.total != null\n}\n\nfunction isComparable(detail?: ScoreAttributeDetail): boolean {\n return hasLevel(detail) || isFraction(detail)\n}\n\nexport const ChatScoreBreakdown = ({ percent, detail, labels, typologyId }: ChatScoreBreakdownProps) => {\n // A packaging product hides food attributes (temperature/cutting/cooking) and shows the\n // numeric specs, and vice versa. Two independent signals mark a packaging product, combined\n // so neither can wrongly override the other: the AO product typology (authoritative, and the\n // only signal when no numeric spec is comparable), and the presence of a comparable numeric\n // spec (covers cases where the typology is absent or not sent as the expected value).\n const isPackaging =\n Number(typologyId) === PACKAGING_TYPOLOGY_ID || PACKAGING_ONLY_KEYS.some(key => detail[key]?.level != null)\n const hiddenKeys = new Set<ScoreAttributeKey>(isPackaging ? FOOD_ONLY_KEYS : PACKAGING_ONLY_KEYS)\n const visibleKeys = ATTRIBUTE_ORDER.filter(key => !hiddenKeys.has(key))\n\n const compared = visibleKeys.filter(key => isComparable(detail[key]))\n const notSpecified = visibleKeys.filter(key => !isComparable(detail[key]) && labels.attributes[key] != null)\n\n return (\n <Box\n bg=\"white\"\n borderRadius=\"radius-8\"\n p=\"space-16\"\n minW=\"220px\"\n maxW=\"240px\"\n css={{ '& *': { fontFamily: 'inherit' } }}\n >\n <HStack justify=\"space-between\" alignItems=\"baseline\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.md\" fontWeight=\"bold\">\n {labels.title}\n </Text>\n <Text as=\"span\" fontSize=\"body.lg\" fontWeight=\"medium\" style={{ color: getHeadlineColor(percent) }}>\n {Math.round(percent)} %\n </Text>\n </HStack>\n\n <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />\n\n {compared.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.compared}\n </Text>\n {compared.map(key => {\n const entry = detail[key]\n if (hasLevel(entry)) {\n const level = entry.level as ScoreLevel\n const colors = LEVEL_COLORS[level]\n return (\n <HStack key={key} h=\"18px\" alignItems=\"center\" gap=\"space-8\" justify=\"space-between\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box\n display=\"flex\"\n alignItems=\"center\"\n justifyContent=\"center\"\n h=\"100%\"\n px=\"space-6\"\n borderRadius=\"full\"\n flexShrink=\"0\"\n style={{ backgroundColor: colors.bg }}\n >\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n style={{ color: colors.color, whiteSpace: 'nowrap', lineHeight: 1 }}\n >\n {labels.levels?.[level] ?? level}\n </Text>\n </Box>\n </HStack>\n )\n }\n\n const matched = entry.matched as number\n const total = entry.total as number\n const ratioPercent = total > 0 ? (matched / total) * 100 : 0\n return (\n <HStack key={key} h=\"18px\" alignItems=\"center\" gap=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\" minW=\"80px\">\n {labels.attributes[key]}\n </Text>\n <Box flex=\"1\" h=\"3px\" bg=\"grey.100\" borderRadius=\"full\" overflow=\"hidden\">\n <Box\n h=\"100%\"\n borderRadius=\"full\"\n style={{ width: `${ratioPercent}%`, background: getBarColor(ratioPercent) }}\n />\n </Box>\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n minW=\"40px\"\n textAlign=\"right\"\n style={{ color: getBarColor(ratioPercent), lineHeight: 1 }}\n >\n {matched}/{total}\n </Text>\n </HStack>\n )\n })}\n </VStack>\n )}\n\n {compared.length > 0 && notSpecified.length > 0 && <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />}\n\n {notSpecified.length > 0 && (\n <VStack alignItems=\"stretch\" gap=\"space-4\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.notSpecified}\n </Text>\n <HStack flexWrap=\"wrap\" gap=\"space-4\">\n {notSpecified.map(key => (\n <Text\n key={key}\n as=\"span\"\n fontSize=\"body.sm\"\n color=\"grey.400\"\n border=\"1px solid\"\n borderColor=\"grey.100\"\n px=\"space-8\"\n py=\"2px\"\n borderRadius=\"full\"\n >\n {labels.attributes[key]}\n </Text>\n ))}\n </HStack>\n </VStack>\n )}\n\n {labels.footer && (\n <>\n <Box h=\"1px\" bg=\"grey.100\" mt=\"space-8\" mb=\"space-8\" />\n <Text as=\"span\" fontSize=\"9px\" color=\"grey.300\" style={{ lineHeight: 1 }}>\n {labels.footer}\n </Text>\n </>\n )}\n </Box>\n )\n}\n"],"mappings":";;;;;AA2CA,IAAM,IAAwB,GAExB,IAAuC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAGM,IAAsC;CAAC;CAAe;CAAW;AAAS,GAE1E,IAAkD;CAAC;CAAe;CAAe;AAAiB,GAElG,IAAkE;CACtE,MAAM;EAAE,IAAI;EAAW,OAAO;CAAU;CACxC,QAAQ;EAAE,IAAI;EAAW,OAAO;CAAU;CAC1C,SAAS;EAAE,IAAI;EAAW,OAAO;CAAU;CAC3C,mBAAmB;EAAE,IAAI;EAAW,OAAO;CAAU;AACvD;AAEA,SAAS,EAAiB,GAAyB;CAGjD,OAFI,KAAW,KAAW,YACtB,KAAW,KAAW,YACnB;AACT;AAEA,SAAS,EAAY,GAA8B;CAGjD,OAFI,KAAgB,KAAW,YAC3B,KAAgB,KAAW,YACxB;AACT;AAEA,SAAS,EAAS,GAAwC;CACxD,OAAO,GAAQ,SAAS;AAC1B;AAEA,SAAS,EAAW,GAAwC;CAC1D,OAAO,GAAQ,WAAW,QAAQ,GAAQ,SAAS;AACrD;AAEA,SAAS,EAAa,GAAwC;CAC5D,OAAO,EAAS,CAAM,KAAK,EAAW,CAAM;AAC9C;AAEA,IAAa,KAAsB,EAAE,YAAS,WAAQ,WAAQ,oBAA0C;CAMtG,IAAM,IACJ,OAAO,CAAU,MAAM,KAAyB,EAAoB,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,OAAM;eACxD,EAAO;IACJ,CAAA,GACN,kBAAC,GAAD;KAAQ,UAAS;KAAO,KAAI;eACzB,EAAa,KAAI,MAChB,kBAAC,GAAD;MAEE,IAAG;MACH,UAAS;MACT,OAAM;MACN,QAAO;MACP,aAAY;MACZ,IAAG;MACH,IAAG;MACH,cAAa;gBAEZ,EAAO,WAAW;KACf,GAXC,CAWD,CACP;IACK,CAAA,CACF;;GAGT,EAAO,UACN,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD;IAAK,GAAE;IAAM,IAAG;IAAW,IAAG;IAAU,IAAG;GAAW,CAAA,GACtD,kBAAC,GAAD;IAAM,IAAG;IAAO,UAAS;IAAM,OAAM;IAAW,OAAO,EAAE,YAAY,EAAE;cACpE,EAAO;GACJ,CAAA,CACN,EAAA,CAAA;EAED;;AAET"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";const e=require("../text/Text.cjs"),t=require("../popover/Popover.cjs"),n=require("./SupplierRatingBreakdown.cjs");let r=require("@stokelp/styled-system/jsx"),i=require("react"),a=require("react/jsx-runtime");function o(e){let t=e/5;return t>=.8?{bg:`#E6F3D9`,color:`#3B6D11`}:t>=.6?{bg:`#FBF1CC`,color:`#92750C`}:t>=.4?{bg:`#FDF0E0`,color:`#C2740C`}:{bg:`#FCEBEB`,color:`#A32D2D`}}function s({rating:s,responseRate:c,labels:l}){let[u,d]=(0,i.useState)(!1),f=(0,i.useRef)(null),p=(0,i.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null)},[]),m=(0,i.useCallback)(()=>{p(),f.current=setTimeout(()=>d(!1),120)},[p]);(0,i.useEffect)(()=>p,[p]);let h=e=>{e.pointerType===`mouse`&&(p(),d(!0))},g=e=>{e.pointerType===`mouse`&&m()},_=s.insufficientData||s.overall==null,v=l?.insufficientData??n.DEFAULT_SUPPLIER_RATING_LABELS.insufficientData,y=_?{bg:`#F1F2F4`,color:`#5B6472`}:o(s.overall);return(0,a.jsxs)(t.Popover,{open:u,onOpenChange:e=>d(e.open),positioning:{placement:`top-end`,gutter:8},autoFocus:!1,restoreFocus:!1,lazyMount:!0,unmountOnExit:!0,children:[(0,a.jsx)(t.PopoverTrigger,{asChild:!0,children:(0,a.jsx)(r.Box,{display:`inline-flex`,alignItems:`center`,w:`fit-content`,maxW:`100%`,px:`space-8`,py:`space-2`,borderRadius:`full`,tabIndex:0,cursor:`default`,style:{backgroundColor:y.bg},onPointerEnter:h,onPointerLeave:g,onFocus:()=>{p(),d(!0)},onBlur:()=>d(!1),children:(0,a.jsx)(e.Text,{size:`sm`,bold:!0,whiteSpace:`nowrap`,style:{color:y.color},children:_?v:`${n.formatOverall(s.overall)} ★`})})}),(0,a.jsx)(t.PopoverContent,{className:`panda-preflight-enabled`,zIndex:1e4,p:`0`,bg:`transparent`,border:`none`,borderRadius:`radius-8`,boxShadow:`0px 8px 16px 4px #1624861A`,onPointerEnter:h,onPointerLeave:g,children:(0,a.jsx)(n.SupplierRatingBreakdown,{rating:s,responseRate:c,labels:l})})]})}exports.SupplierRatingBadge=s;
|
|
2
|
+
//# sourceMappingURL=SupplierRatingBadge.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SupplierRatingBadge.cjs","names":[],"sources":["../../../src/components/supplier-rating-badge/SupplierRatingBadge.tsx"],"sourcesContent":["import { Box } from '@stokelp/styled-system/jsx'\nimport { PointerEvent, useCallback, useEffect, useRef, useState } from 'react'\n\nimport { Popover, PopoverContent, PopoverTrigger, Text } from '~/components'\n\nimport {\n DEFAULT_SUPPLIER_RATING_LABELS,\n formatOverall,\n SUPPLIER_RATING_MAX,\n SupplierRatingBreakdown,\n type SupplierRating,\n type SupplierRatingLabels,\n} from './SupplierRatingBreakdown'\n\nexport type SupplierRatingBadgeProps = {\n rating: SupplierRating\n /** Optional original response rate (0..100) reminded inside the breakdown. */\n responseRate?: number\n labels?: Partial<SupplierRatingLabels>\n}\n\nfunction getBadgeColors(overall: number): { bg: string; color: string } {\n const ratio = overall / SUPPLIER_RATING_MAX\n if (ratio >= 0.8) return { bg: '#E6F3D9', color: '#3B6D11' }\n if (ratio >= 0.6) return { bg: '#FBF1CC', color: '#92750C' }\n if (ratio >= 0.4) return { bg: '#FDF0E0', color: '#C2740C' }\n return { bg: '#FCEBEB', color: '#A32D2D' }\n}\n\n/** Compact supplier-rating pill (note /5) with an accessible, keyboard-openable breakdown popover. */\nexport function SupplierRatingBadge({ rating, responseRate, labels }: SupplierRatingBadgeProps) {\n const [open, setOpen] = useState(false)\n const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n const cancelClose = useCallback(() => {\n if (closeTimer.current) {\n clearTimeout(closeTimer.current)\n closeTimer.current = null\n }\n }, [])\n\n const scheduleClose = useCallback(() => {\n cancelClose()\n closeTimer.current = setTimeout(() => setOpen(false), 120)\n }, [cancelClose])\n\n useEffect(() => cancelClose, [cancelClose])\n\n const openOnMouse = (e: PointerEvent) => {\n if (e.pointerType !== 'mouse') return\n cancelClose()\n setOpen(true)\n }\n const closeOnMouse = (e: PointerEvent) => {\n if (e.pointerType !== 'mouse') return\n scheduleClose()\n }\n\n const insufficient = rating.insufficientData || rating.overall == null\n const insufficientLabel = labels?.insufficientData ?? DEFAULT_SUPPLIER_RATING_LABELS.insufficientData\n const colors = insufficient ? { bg: '#F1F2F4', color: '#5B6472' } : getBadgeColors(rating.overall as number)\n\n return (\n <Popover\n open={open}\n onOpenChange={e => setOpen(e.open)}\n positioning={{ placement: 'top-end', gutter: 8 }}\n autoFocus={false}\n restoreFocus={false}\n lazyMount\n unmountOnExit\n >\n <PopoverTrigger asChild>\n <Box\n display=\"inline-flex\"\n alignItems=\"center\"\n w=\"fit-content\"\n maxW=\"100%\"\n px=\"space-8\"\n py=\"space-2\"\n borderRadius=\"full\"\n tabIndex={0}\n cursor=\"default\"\n style={{ backgroundColor: colors.bg }}\n onPointerEnter={openOnMouse}\n onPointerLeave={closeOnMouse}\n onFocus={() => {\n cancelClose()\n setOpen(true)\n }}\n onBlur={() => setOpen(false)}\n >\n <Text size=\"sm\" bold whiteSpace=\"nowrap\" style={{ color: colors.color }}>\n {insufficient ? insufficientLabel : `${formatOverall(rating.overall as number)} ★`}\n </Text>\n </Box>\n </PopoverTrigger>\n <PopoverContent\n className=\"panda-preflight-enabled\"\n zIndex={10000}\n p=\"0\"\n bg=\"transparent\"\n border=\"none\"\n borderRadius=\"radius-8\"\n boxShadow=\"0px 8px 16px 4px #1624861A\"\n onPointerEnter={openOnMouse}\n onPointerLeave={closeOnMouse}\n >\n <SupplierRatingBreakdown rating={rating} responseRate={responseRate} labels={labels} />\n </PopoverContent>\n </Popover>\n )\n}\n"],"mappings":"8NAqBA,SAAS,EAAe,EAAgD,CACtE,IAAM,EAAQ,EAAA,EAId,OAHI,GAAS,GAAY,CAAE,GAAI,UAAW,MAAO,SAAU,EACvD,GAAS,GAAY,CAAE,GAAI,UAAW,MAAO,SAAU,EACvD,GAAS,GAAY,CAAE,GAAI,UAAW,MAAO,SAAU,EACpD,CAAE,GAAI,UAAW,MAAO,SAAU,CAC3C,CAGA,SAAgB,EAAoB,CAAE,SAAQ,eAAc,UAAoC,CAC9F,GAAM,CAAC,EAAM,IAAA,EAAA,EAAA,UAAoB,EAAK,EAChC,GAAA,EAAA,EAAA,QAA0D,IAAI,EAE9D,GAAA,EAAA,EAAA,iBAAgC,CACpC,AAEE,EAAW,WADX,aAAa,EAAW,OAAO,EACV,KAEzB,EAAG,CAAC,CAAC,EAEC,GAAA,EAAA,EAAA,iBAAkC,CACtC,EAAY,EACZ,EAAW,QAAU,eAAiB,EAAQ,EAAK,EAAG,GAAG,CAC3D,EAAG,CAAC,CAAW,CAAC,GAEhB,EAAA,EAAA,eAAgB,EAAa,CAAC,CAAW,CAAC,EAE1C,IAAM,EAAe,GAAoB,CACnC,EAAE,cAAgB,UACtB,EAAY,EACZ,EAAQ,EAAI,EACd,EACM,EAAgB,GAAoB,CACpC,EAAE,cAAgB,SACtB,EAAc,CAChB,EAEM,EAAe,EAAO,kBAAoB,EAAO,SAAW,KAC5D,EAAoB,GAAQ,kBAAoB,EAAA,+BAA+B,iBAC/E,EAAS,EAAe,CAAE,GAAI,UAAW,MAAO,SAAU,EAAI,EAAe,EAAO,OAAiB,EAE3G,OACE,EAAA,EAAA,MAAC,EAAA,QAAD,CACQ,OACN,aAAc,GAAK,EAAQ,EAAE,IAAI,EACjC,YAAa,CAAE,UAAW,UAAW,OAAQ,CAAE,EAC/C,UAAW,GACX,aAAc,GACd,UAAA,GACA,cAAA,YAPF,EASE,EAAA,EAAA,KAAC,EAAA,eAAD,CAAgB,QAAA,aACd,EAAA,EAAA,KAAC,EAAA,IAAD,CACE,QAAQ,cACR,WAAW,SACX,EAAE,cACF,KAAK,OACL,GAAG,UACH,GAAG,UACH,aAAa,OACb,SAAU,EACV,OAAO,UACP,MAAO,CAAE,gBAAiB,EAAO,EAAG,EACpC,eAAgB,EAChB,eAAgB,EAChB,YAAe,CACb,EAAY,EACZ,EAAQ,EAAI,CACd,EACA,WAAc,EAAQ,EAAK,YAE3B,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,KAAK,KAAK,KAAA,GAAK,WAAW,SAAS,MAAO,CAAE,MAAO,EAAO,KAAM,WACnE,EAAe,EAAoB,GAAG,EAAA,cAAc,EAAO,OAAiB,EAAE,GAC3E,CAAA,CACH,CAAA,CACS,CAAA,GAChB,EAAA,EAAA,KAAC,EAAA,eAAD,CACE,UAAU,0BACV,OAAQ,IACR,EAAE,IACF,GAAG,cACH,OAAO,OACP,aAAa,WACb,UAAU,6BACV,eAAgB,EAChB,eAAgB,YAEhB,EAAA,EAAA,KAAC,EAAA,wBAAD,CAAiC,SAAsB,eAAsB,QAAS,CAAA,CACxE,CAAA,CACT,GAEb"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SupplierRating, SupplierRatingLabels } from './SupplierRatingBreakdown';
|
|
2
|
+
export type SupplierRatingBadgeProps = {
|
|
3
|
+
rating: SupplierRating;
|
|
4
|
+
/** Optional original response rate (0..100) reminded inside the breakdown. */
|
|
5
|
+
responseRate?: number;
|
|
6
|
+
labels?: Partial<SupplierRatingLabels>;
|
|
7
|
+
};
|
|
8
|
+
/** Compact supplier-rating pill (note /5) with an accessible, keyboard-openable breakdown popover. */
|
|
9
|
+
export declare function SupplierRatingBadge({ rating, responseRate, labels }: SupplierRatingBadgeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Text as e } from "../text/Text.js";
|
|
3
|
+
import { Popover as t, PopoverContent as n, PopoverTrigger as r } from "../popover/Popover.js";
|
|
4
|
+
import { DEFAULT_SUPPLIER_RATING_LABELS as i, SupplierRatingBreakdown as a, formatOverall as o } from "./SupplierRatingBreakdown.js";
|
|
5
|
+
import { Box as s } from "@stokelp/styled-system/jsx";
|
|
6
|
+
import { useCallback as c, useEffect as l, useRef as u, useState as d } from "react";
|
|
7
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
8
|
+
//#region src/components/supplier-rating-badge/SupplierRatingBadge.tsx
|
|
9
|
+
function m(e) {
|
|
10
|
+
let t = e / 5;
|
|
11
|
+
return t >= .8 ? {
|
|
12
|
+
bg: "#E6F3D9",
|
|
13
|
+
color: "#3B6D11"
|
|
14
|
+
} : t >= .6 ? {
|
|
15
|
+
bg: "#FBF1CC",
|
|
16
|
+
color: "#92750C"
|
|
17
|
+
} : t >= .4 ? {
|
|
18
|
+
bg: "#FDF0E0",
|
|
19
|
+
color: "#C2740C"
|
|
20
|
+
} : {
|
|
21
|
+
bg: "#FCEBEB",
|
|
22
|
+
color: "#A32D2D"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function h({ rating: h, responseRate: g, labels: _ }) {
|
|
26
|
+
let [v, y] = d(!1), b = u(null), x = c(() => {
|
|
27
|
+
b.current &&= (clearTimeout(b.current), null);
|
|
28
|
+
}, []), S = c(() => {
|
|
29
|
+
x(), b.current = setTimeout(() => y(!1), 120);
|
|
30
|
+
}, [x]);
|
|
31
|
+
l(() => x, [x]);
|
|
32
|
+
let C = (e) => {
|
|
33
|
+
e.pointerType === "mouse" && (x(), y(!0));
|
|
34
|
+
}, w = (e) => {
|
|
35
|
+
e.pointerType === "mouse" && S();
|
|
36
|
+
}, T = h.insufficientData || h.overall == null, E = _?.insufficientData ?? i.insufficientData, D = T ? {
|
|
37
|
+
bg: "#F1F2F4",
|
|
38
|
+
color: "#5B6472"
|
|
39
|
+
} : m(h.overall);
|
|
40
|
+
return /* @__PURE__ */ p(t, {
|
|
41
|
+
open: v,
|
|
42
|
+
onOpenChange: (e) => y(e.open),
|
|
43
|
+
positioning: {
|
|
44
|
+
placement: "top-end",
|
|
45
|
+
gutter: 8
|
|
46
|
+
},
|
|
47
|
+
autoFocus: !1,
|
|
48
|
+
restoreFocus: !1,
|
|
49
|
+
lazyMount: !0,
|
|
50
|
+
unmountOnExit: !0,
|
|
51
|
+
children: [/* @__PURE__ */ f(r, {
|
|
52
|
+
asChild: !0,
|
|
53
|
+
children: /* @__PURE__ */ f(s, {
|
|
54
|
+
display: "inline-flex",
|
|
55
|
+
alignItems: "center",
|
|
56
|
+
w: "fit-content",
|
|
57
|
+
maxW: "100%",
|
|
58
|
+
px: "space-8",
|
|
59
|
+
py: "space-2",
|
|
60
|
+
borderRadius: "full",
|
|
61
|
+
tabIndex: 0,
|
|
62
|
+
cursor: "default",
|
|
63
|
+
style: { backgroundColor: D.bg },
|
|
64
|
+
onPointerEnter: C,
|
|
65
|
+
onPointerLeave: w,
|
|
66
|
+
onFocus: () => {
|
|
67
|
+
x(), y(!0);
|
|
68
|
+
},
|
|
69
|
+
onBlur: () => y(!1),
|
|
70
|
+
children: /* @__PURE__ */ f(e, {
|
|
71
|
+
size: "sm",
|
|
72
|
+
bold: !0,
|
|
73
|
+
whiteSpace: "nowrap",
|
|
74
|
+
style: { color: D.color },
|
|
75
|
+
children: T ? E : `${o(h.overall)} ★`
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
}), /* @__PURE__ */ f(n, {
|
|
79
|
+
className: "panda-preflight-enabled",
|
|
80
|
+
zIndex: 1e4,
|
|
81
|
+
p: "0",
|
|
82
|
+
bg: "transparent",
|
|
83
|
+
border: "none",
|
|
84
|
+
borderRadius: "radius-8",
|
|
85
|
+
boxShadow: "0px 8px 16px 4px #1624861A",
|
|
86
|
+
onPointerEnter: C,
|
|
87
|
+
onPointerLeave: w,
|
|
88
|
+
children: /* @__PURE__ */ f(a, {
|
|
89
|
+
rating: h,
|
|
90
|
+
responseRate: g,
|
|
91
|
+
labels: _
|
|
92
|
+
})
|
|
93
|
+
})]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { h as SupplierRatingBadge };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=SupplierRatingBadge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SupplierRatingBadge.js","names":[],"sources":["../../../src/components/supplier-rating-badge/SupplierRatingBadge.tsx"],"sourcesContent":["import { Box } from '@stokelp/styled-system/jsx'\nimport { PointerEvent, useCallback, useEffect, useRef, useState } from 'react'\n\nimport { Popover, PopoverContent, PopoverTrigger, Text } from '~/components'\n\nimport {\n DEFAULT_SUPPLIER_RATING_LABELS,\n formatOverall,\n SUPPLIER_RATING_MAX,\n SupplierRatingBreakdown,\n type SupplierRating,\n type SupplierRatingLabels,\n} from './SupplierRatingBreakdown'\n\nexport type SupplierRatingBadgeProps = {\n rating: SupplierRating\n /** Optional original response rate (0..100) reminded inside the breakdown. */\n responseRate?: number\n labels?: Partial<SupplierRatingLabels>\n}\n\nfunction getBadgeColors(overall: number): { bg: string; color: string } {\n const ratio = overall / SUPPLIER_RATING_MAX\n if (ratio >= 0.8) return { bg: '#E6F3D9', color: '#3B6D11' }\n if (ratio >= 0.6) return { bg: '#FBF1CC', color: '#92750C' }\n if (ratio >= 0.4) return { bg: '#FDF0E0', color: '#C2740C' }\n return { bg: '#FCEBEB', color: '#A32D2D' }\n}\n\n/** Compact supplier-rating pill (note /5) with an accessible, keyboard-openable breakdown popover. */\nexport function SupplierRatingBadge({ rating, responseRate, labels }: SupplierRatingBadgeProps) {\n const [open, setOpen] = useState(false)\n const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n const cancelClose = useCallback(() => {\n if (closeTimer.current) {\n clearTimeout(closeTimer.current)\n closeTimer.current = null\n }\n }, [])\n\n const scheduleClose = useCallback(() => {\n cancelClose()\n closeTimer.current = setTimeout(() => setOpen(false), 120)\n }, [cancelClose])\n\n useEffect(() => cancelClose, [cancelClose])\n\n const openOnMouse = (e: PointerEvent) => {\n if (e.pointerType !== 'mouse') return\n cancelClose()\n setOpen(true)\n }\n const closeOnMouse = (e: PointerEvent) => {\n if (e.pointerType !== 'mouse') return\n scheduleClose()\n }\n\n const insufficient = rating.insufficientData || rating.overall == null\n const insufficientLabel = labels?.insufficientData ?? DEFAULT_SUPPLIER_RATING_LABELS.insufficientData\n const colors = insufficient ? { bg: '#F1F2F4', color: '#5B6472' } : getBadgeColors(rating.overall as number)\n\n return (\n <Popover\n open={open}\n onOpenChange={e => setOpen(e.open)}\n positioning={{ placement: 'top-end', gutter: 8 }}\n autoFocus={false}\n restoreFocus={false}\n lazyMount\n unmountOnExit\n >\n <PopoverTrigger asChild>\n <Box\n display=\"inline-flex\"\n alignItems=\"center\"\n w=\"fit-content\"\n maxW=\"100%\"\n px=\"space-8\"\n py=\"space-2\"\n borderRadius=\"full\"\n tabIndex={0}\n cursor=\"default\"\n style={{ backgroundColor: colors.bg }}\n onPointerEnter={openOnMouse}\n onPointerLeave={closeOnMouse}\n onFocus={() => {\n cancelClose()\n setOpen(true)\n }}\n onBlur={() => setOpen(false)}\n >\n <Text size=\"sm\" bold whiteSpace=\"nowrap\" style={{ color: colors.color }}>\n {insufficient ? insufficientLabel : `${formatOverall(rating.overall as number)} ★`}\n </Text>\n </Box>\n </PopoverTrigger>\n <PopoverContent\n className=\"panda-preflight-enabled\"\n zIndex={10000}\n p=\"0\"\n bg=\"transparent\"\n border=\"none\"\n borderRadius=\"radius-8\"\n boxShadow=\"0px 8px 16px 4px #1624861A\"\n onPointerEnter={openOnMouse}\n onPointerLeave={closeOnMouse}\n >\n <SupplierRatingBreakdown rating={rating} responseRate={responseRate} labels={labels} />\n </PopoverContent>\n </Popover>\n )\n}\n"],"mappings":";;;;;;;;AAqBA,SAAS,EAAe,GAAgD;CACtE,IAAM,IAAQ,IAAA;CAId,OAHI,KAAS,KAAY;EAAE,IAAI;EAAW,OAAO;CAAU,IACvD,KAAS,KAAY;EAAE,IAAI;EAAW,OAAO;CAAU,IACvD,KAAS,KAAY;EAAE,IAAI;EAAW,OAAO;CAAU,IACpD;EAAE,IAAI;EAAW,OAAO;CAAU;AAC3C;AAGA,SAAgB,EAAoB,EAAE,WAAQ,iBAAc,aAAoC;CAC9F,IAAM,CAAC,GAAM,KAAW,EAAS,EAAK,GAChC,IAAa,EAA6C,IAAI,GAE9D,IAAc,QAAkB;EACpC,AAEE,EAAW,aADX,aAAa,EAAW,OAAO,GACV;CAEzB,GAAG,CAAC,CAAC,GAEC,IAAgB,QAAkB;EAEtC,AADA,EAAY,GACZ,EAAW,UAAU,iBAAiB,EAAQ,EAAK,GAAG,GAAG;CAC3D,GAAG,CAAC,CAAW,CAAC;CAEhB,QAAgB,GAAa,CAAC,CAAW,CAAC;CAE1C,IAAM,KAAe,MAAoB;EACnC,EAAE,gBAAgB,YACtB,EAAY,GACZ,EAAQ,EAAI;CACd,GACM,KAAgB,MAAoB;EACpC,EAAE,gBAAgB,WACtB,EAAc;CAChB,GAEM,IAAe,EAAO,oBAAoB,EAAO,WAAW,MAC5D,IAAoB,GAAQ,oBAAoB,EAA+B,kBAC/E,IAAS,IAAe;EAAE,IAAI;EAAW,OAAO;CAAU,IAAI,EAAe,EAAO,OAAiB;CAE3G,OACE,kBAAC,GAAD;EACQ;EACN,eAAc,MAAK,EAAQ,EAAE,IAAI;EACjC,aAAa;GAAE,WAAW;GAAW,QAAQ;EAAE;EAC/C,WAAW;EACX,cAAc;EACd,WAAA;EACA,eAAA;YAPF,CASE,kBAAC,GAAD;GAAgB,SAAA;aACd,kBAAC,GAAD;IACE,SAAQ;IACR,YAAW;IACX,GAAE;IACF,MAAK;IACL,IAAG;IACH,IAAG;IACH,cAAa;IACb,UAAU;IACV,QAAO;IACP,OAAO,EAAE,iBAAiB,EAAO,GAAG;IACpC,gBAAgB;IAChB,gBAAgB;IAChB,eAAe;KAEb,AADA,EAAY,GACZ,EAAQ,EAAI;IACd;IACA,cAAc,EAAQ,EAAK;cAE3B,kBAAC,GAAD;KAAM,MAAK;KAAK,MAAA;KAAK,YAAW;KAAS,OAAO,EAAE,OAAO,EAAO,MAAM;eACnE,IAAe,IAAoB,GAAG,EAAc,EAAO,OAAiB,EAAE;IAC3E,CAAA;GACH,CAAA;EACS,CAAA,GAChB,kBAAC,GAAD;GACE,WAAU;GACV,QAAQ;GACR,GAAE;GACF,IAAG;GACH,QAAO;GACP,cAAa;GACb,WAAU;GACV,gBAAgB;GAChB,gBAAgB;aAEhB,kBAAC,GAAD;IAAiC;IAAsB;IAAsB;GAAS,CAAA;EACxE,CAAA,CACT;;AAEb"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";const e=require("../text/Text.cjs"),t=require("../icon/Icon.cjs"),n=require("../../node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/CheckCircleIcon.cjs"),r=require("../../node_modules/.pnpm/@heroicons_react@2.2.0_react@19.2.6/node_modules/@heroicons/react/24/outline/esm/XCircleIcon.cjs");let i=require("@stokelp/styled-system/jsx"),a=require("react/jsx-runtime");var o=5,s={title:`Note fournisseur`,insufficientData:`Pas encore assez de données`,componentsTitle:`Détail de la note`,completionTitle:`Complétion du compte`,responseRate:`Taux de réponse`,notAvailable:`—`,components:{responseRate:`Taux de réponse`,responseDelay:`Délai de réponse`,completion:`Complétion du compte`},completion:{profile:`Profil (photo et description)`,locationContacts:`Localisation et contact`,legalBanking:`Coordonnées légales et bancaires`,business:`Secteur, certificat et intérêt produit`}},c={responseRate:40,responseDelay:30,completion:30},l=[`responseRate`,`responseDelay`,`completion`],u=[`profile`,`locationContacts`,`legalBanking`,`business`];function d(e){return e.toFixed(1).replace(`.`,`,`)}function f(e){let t=e/5;return t>=.7?`#3B6D11`:t>=.4?`#854F0B`:`#A32D2D`}function p(e){return e>=70?`#639922`:e>=40?`#BA7517`:`#E24B4A`}var m=({rating:o,responseRate:m,labels:h})=>{let g={...s,...h,components:{...s.components,...h?.components},completion:{...s.completion,...h?.completion}},_={responseRate:o.responseRateScore,responseDelay:o.responseDelayScore,completion:o.completionScore};return(0,a.jsxs)(i.Box,{bg:`white`,borderRadius:`radius-8`,p:`space-16`,minW:`240px`,maxW:`260px`,css:{"& *":{fontFamily:`inherit`}},children:[(0,a.jsxs)(i.HStack,{justify:`space-between`,alignItems:`baseline`,mb:`space-8`,children:[(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.md`,fontWeight:`bold`,children:g.title}),o.insufficientData||o.overall==null?(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`medium`,color:`grey.400`,children:g.insufficientData}):(0,a.jsxs)(e.Text,{as:`span`,fontSize:`body.lg`,fontWeight:`medium`,style:{color:f(o.overall)},children:[d(o.overall),` / `,5,` ★`]})]}),(0,a.jsx)(i.Box,{h:`1px`,bg:`grey.100`,mb:`space-8`}),(0,a.jsxs)(i.VStack,{alignItems:`stretch`,gap:`space-8`,mb:`space-8`,children:[(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`bold`,color:`grey.400`,children:g.componentsTitle}),l.map(t=>{let n=_[t],r=n!=null,o=r?Math.round(n*100):0;return(0,a.jsxs)(i.VStack,{alignItems:`stretch`,gap:`space-2`,children:[(0,a.jsxs)(i.HStack,{justify:`space-between`,alignItems:`baseline`,children:[(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,color:`grey.500`,children:g.components[t]}),(0,a.jsxs)(e.Text,{as:`span`,fontSize:`body.sm`,color:`grey.300`,children:[c[t],` %`]})]}),(0,a.jsxs)(i.HStack,{alignItems:`center`,gap:`space-8`,children:[(0,a.jsx)(i.Box,{flex:`1`,h:`3px`,bg:`grey.100`,borderRadius:`full`,overflow:`hidden`,children:(0,a.jsx)(i.Box,{h:`100%`,borderRadius:`full`,style:{width:r?`${o}%`:`0%`,background:p(o)}})}),(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`medium`,minW:`40px`,textAlign:`right`,style:{color:r?p(o):void 0},color:r?void 0:`grey.300`,children:r?`${o} %`:g.notAvailable})]})]},t)})]}),m!=null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i.Box,{h:`1px`,bg:`grey.100`,mb:`space-8`}),(0,a.jsxs)(i.HStack,{justify:`space-between`,alignItems:`baseline`,mb:`space-8`,children:[(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,color:`grey.500`,children:g.responseRate}),(0,a.jsxs)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`medium`,color:`grey.500`,children:[Math.round(m),` %`]})]})]}),(0,a.jsx)(i.Box,{h:`1px`,bg:`grey.100`,mb:`space-8`}),(0,a.jsxs)(i.VStack,{alignItems:`stretch`,gap:`space-4`,children:[(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,fontWeight:`bold`,color:`grey.400`,children:g.completionTitle}),u.map(s=>{let c=o.completion[s];return(0,a.jsxs)(i.HStack,{alignItems:`center`,gap:`space-8`,children:[(0,a.jsx)(t.Icon,{size:`sm`,color:c?`success.500`:`grey.300`,flexShrink:`0`,children:c?(0,a.jsx)(n.default,{}):(0,a.jsx)(r.default,{})}),(0,a.jsx)(e.Text,{as:`span`,fontSize:`body.sm`,color:c?`grey.500`:`grey.400`,children:g.completion[s]})]},s)})]}),g.footer&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i.Box,{h:`1px`,bg:`grey.100`,mt:`space-8`,mb:`space-8`}),(0,a.jsx)(e.Text,{as:`span`,fontSize:`9px`,color:`grey.300`,style:{lineHeight:1},children:g.footer})]})]})};exports.DEFAULT_SUPPLIER_RATING_LABELS=s,exports.SUPPLIER_RATING_MAX=o,exports.SUPPLIER_RATING_WEIGHTS=c,exports.SupplierRatingBreakdown=m,exports.formatOverall=d,exports.getHeadlineColor=f;
|
|
2
|
+
//# sourceMappingURL=SupplierRatingBreakdown.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SupplierRatingBreakdown.cjs","names":[],"sources":["../../../src/components/supplier-rating-badge/SupplierRatingBreakdown.tsx"],"sourcesContent":["import { CheckCircleIcon, XCircleIcon } from '@heroicons/react/24/outline'\nimport { Box, HStack, VStack } from '@stokelp/styled-system/jsx'\n\nimport { Icon, Text } from '~/components'\n\nexport const SUPPLIER_RATING_MAX = 5\n\nexport type SupplierRatingComponentKey = 'responseRate' | 'responseDelay' | 'completion'\n\nexport type SupplierRatingCompletionKey = 'profile' | 'locationContacts' | 'legalBanking' | 'business'\n\nexport type SupplierRatingCompletion = Record<SupplierRatingCompletionKey, boolean>\n\nexport type SupplierRating = {\n /** Overall note out of 5. Absent when insufficientData is true. */\n overall?: number\n /** Response-rate sub-score, 0..1. Absent when insufficientData is true. */\n responseRateScore?: number\n /** Response-delay sub-score, 0..1. Absent when insufficientData is true. */\n responseDelayScore?: number\n /** Account-completion sub-score, 0..1. Always present. */\n completionScore: number\n /** True when the supplier has too few interactions for a reliable note. */\n insufficientData: boolean\n /** Completion checklist shown in the breakdown. */\n completion: SupplierRatingCompletion\n}\n\nexport type SupplierRatingLabels = {\n title: string\n /** Neutral state shown instead of a note when data is insufficient. */\n insufficientData: string\n /** Section heading above the three weighted sub-scores. */\n componentsTitle: string\n /** Section heading above the completion checklist. */\n completionTitle: string\n /** Label for the \"original response rate\" reminder row. */\n responseRate: string\n /** Suffix used for the \"not enough data yet\" sub-score value (e.g. \"—\"). */\n notAvailable: string\n components: Record<SupplierRatingComponentKey, string>\n completion: Record<SupplierRatingCompletionKey, string>\n footer?: string\n}\n\nexport const DEFAULT_SUPPLIER_RATING_LABELS: SupplierRatingLabels = {\n title: 'Note fournisseur',\n insufficientData: 'Pas encore assez de données',\n componentsTitle: 'Détail de la note',\n completionTitle: 'Complétion du compte',\n responseRate: 'Taux de réponse',\n notAvailable: '—',\n components: {\n responseRate: 'Taux de réponse',\n responseDelay: 'Délai de réponse',\n completion: 'Complétion du compte',\n },\n completion: {\n profile: 'Profil (photo et description)',\n locationContacts: 'Localisation et contact',\n legalBanking: 'Coordonnées légales et bancaires',\n business: 'Secteur, certificat et intérêt produit',\n },\n}\n\n/** Weights (in %) of each sub-score in the overall note. */\nexport const SUPPLIER_RATING_WEIGHTS: Record<SupplierRatingComponentKey, number> = {\n responseRate: 40,\n responseDelay: 30,\n completion: 30,\n}\n\nconst COMPONENT_ORDER: SupplierRatingComponentKey[] = ['responseRate', 'responseDelay', 'completion']\n\nconst COMPLETION_ORDER: SupplierRatingCompletionKey[] = ['profile', 'locationContacts', 'legalBanking', 'business']\n\nexport function formatOverall(overall: number): string {\n return overall.toFixed(1).replace('.', ',')\n}\n\nexport function getHeadlineColor(overall: number): string {\n const ratio = overall / SUPPLIER_RATING_MAX\n if (ratio >= 0.7) return '#3B6D11'\n if (ratio >= 0.4) return '#854F0B'\n return '#A32D2D'\n}\n\nfunction getBarColor(ratioPercent: number): string {\n if (ratioPercent >= 70) return '#639922'\n if (ratioPercent >= 40) return '#BA7517'\n return '#E24B4A'\n}\n\ntype SupplierRatingBreakdownProps = {\n rating: SupplierRating\n /** Optional original response rate (0..100) to remind in the breakdown. */\n responseRate?: number\n labels?: Partial<SupplierRatingLabels>\n}\n\nexport const SupplierRatingBreakdown = ({ rating, responseRate, labels: labelsProp }: SupplierRatingBreakdownProps) => {\n const labels: SupplierRatingLabels = {\n ...DEFAULT_SUPPLIER_RATING_LABELS,\n ...labelsProp,\n components: { ...DEFAULT_SUPPLIER_RATING_LABELS.components, ...labelsProp?.components },\n completion: { ...DEFAULT_SUPPLIER_RATING_LABELS.completion, ...labelsProp?.completion },\n }\n\n const scores: Record<SupplierRatingComponentKey, number | undefined> = {\n responseRate: rating.responseRateScore,\n responseDelay: rating.responseDelayScore,\n completion: rating.completionScore,\n }\n\n return (\n <Box\n bg=\"white\"\n borderRadius=\"radius-8\"\n p=\"space-16\"\n minW=\"240px\"\n maxW=\"260px\"\n css={{ '& *': { fontFamily: 'inherit' } }}\n >\n <HStack justify=\"space-between\" alignItems=\"baseline\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.md\" fontWeight=\"bold\">\n {labels.title}\n </Text>\n {rating.insufficientData || rating.overall == null ? (\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"medium\" color=\"grey.400\">\n {labels.insufficientData}\n </Text>\n ) : (\n <Text as=\"span\" fontSize=\"body.lg\" fontWeight=\"medium\" style={{ color: getHeadlineColor(rating.overall) }}>\n {formatOverall(rating.overall)} / {SUPPLIER_RATING_MAX} ★\n </Text>\n )}\n </HStack>\n\n <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />\n\n <VStack alignItems=\"stretch\" gap=\"space-8\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.componentsTitle}\n </Text>\n {COMPONENT_ORDER.map(key => {\n const score = scores[key]\n const hasScore = score != null\n const ratioPercent = hasScore ? Math.round(score * 100) : 0\n return (\n <VStack key={key} alignItems=\"stretch\" gap=\"space-2\">\n <HStack justify=\"space-between\" alignItems=\"baseline\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\">\n {labels.components[key]}\n </Text>\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.300\">\n {SUPPLIER_RATING_WEIGHTS[key]} %\n </Text>\n </HStack>\n <HStack alignItems=\"center\" gap=\"space-8\">\n <Box flex=\"1\" h=\"3px\" bg=\"grey.100\" borderRadius=\"full\" overflow=\"hidden\">\n <Box\n h=\"100%\"\n borderRadius=\"full\"\n style={{\n width: hasScore ? `${ratioPercent}%` : '0%',\n background: getBarColor(ratioPercent),\n }}\n />\n </Box>\n <Text\n as=\"span\"\n fontSize=\"body.sm\"\n fontWeight=\"medium\"\n minW=\"40px\"\n textAlign=\"right\"\n style={{ color: hasScore ? getBarColor(ratioPercent) : undefined }}\n color={hasScore ? undefined : 'grey.300'}\n >\n {hasScore ? `${ratioPercent} %` : labels.notAvailable}\n </Text>\n </HStack>\n </VStack>\n )\n })}\n </VStack>\n\n {responseRate != null && (\n <>\n <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />\n <HStack justify=\"space-between\" alignItems=\"baseline\" mb=\"space-8\">\n <Text as=\"span\" fontSize=\"body.sm\" color=\"grey.500\">\n {labels.responseRate}\n </Text>\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"medium\" color=\"grey.500\">\n {Math.round(responseRate)} %\n </Text>\n </HStack>\n </>\n )}\n\n <Box h=\"1px\" bg=\"grey.100\" mb=\"space-8\" />\n\n <VStack alignItems=\"stretch\" gap=\"space-4\">\n <Text as=\"span\" fontSize=\"body.sm\" fontWeight=\"bold\" color=\"grey.400\">\n {labels.completionTitle}\n </Text>\n {COMPLETION_ORDER.map(key => {\n const done = rating.completion[key]\n return (\n <HStack key={key} alignItems=\"center\" gap=\"space-8\">\n <Icon size=\"sm\" color={done ? 'success.500' : 'grey.300'} flexShrink=\"0\">\n {done ? <CheckCircleIcon /> : <XCircleIcon />}\n </Icon>\n <Text as=\"span\" fontSize=\"body.sm\" color={done ? 'grey.500' : 'grey.400'}>\n {labels.completion[key]}\n </Text>\n </HStack>\n )\n })}\n </VStack>\n\n {labels.footer && (\n <>\n <Box h=\"1px\" bg=\"grey.100\" mt=\"space-8\" mb=\"space-8\" />\n <Text as=\"span\" fontSize=\"9px\"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AAM,GAAG,OAAO,SAAS,UAAU,WAAW,OAAO,MAAM,oBACxD,EAAO,eACJ,CAAA,EACL,EAAiB,IAAI,GAAO,CAC3B,IAAM,EAAO,EAAO,WAAW,GAC/B,OACE,EAAA,EAAA,MAAC,EAAA,OAAD,CAAkB,WAAW,SAAS,IAAI,mBAA1C,EACE,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,KAAK,KAAK,MAAO,EAAO,cAAgB,WAAY,WAAW,aAClE,GAAO,EAAA,EAAA,KAAC,EAAA,QAAD,CAAkB,CAAA,GAAI,EAAA,EAAA,KAAC,EAAA,QAAD,CAAc,CAAA,CACxC,CAAA,GACN,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,GAAG,OAAO,SAAS,UAAU,MAAO,EAAO,WAAa,oBAC3D,EAAO,WAAW,EACf,CAAA,CACA,GAPK,CAOL,CAEZ,CAAC,CACK,IAEP,EAAO,SACN,EAAA,EAAA,MAAA,EAAA,SAAA,CAAA,SAAA,EACE,EAAA,EAAA,KAAC,EAAA,IAAD,CAAK,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,SAAW,CAAA,GACtD,EAAA,EAAA,KAAC,EAAA,KAAD,CAAM,GAAG,OAAO,SAAS,MAAM,MAAM,WAAW,MAAO,CAAE,WAAY,CAAE,WACpE,EAAO,MACJ,CAAA,CACN,CAAA,CAAA,CAED,GAET"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const SUPPLIER_RATING_MAX = 5;
|
|
2
|
+
export type SupplierRatingComponentKey = 'responseRate' | 'responseDelay' | 'completion';
|
|
3
|
+
export type SupplierRatingCompletionKey = 'profile' | 'locationContacts' | 'legalBanking' | 'business';
|
|
4
|
+
export type SupplierRatingCompletion = Record<SupplierRatingCompletionKey, boolean>;
|
|
5
|
+
export type SupplierRating = {
|
|
6
|
+
/** Overall note out of 5. Absent when insufficientData is true. */
|
|
7
|
+
overall?: number;
|
|
8
|
+
/** Response-rate sub-score, 0..1. Absent when insufficientData is true. */
|
|
9
|
+
responseRateScore?: number;
|
|
10
|
+
/** Response-delay sub-score, 0..1. Absent when insufficientData is true. */
|
|
11
|
+
responseDelayScore?: number;
|
|
12
|
+
/** Account-completion sub-score, 0..1. Always present. */
|
|
13
|
+
completionScore: number;
|
|
14
|
+
/** True when the supplier has too few interactions for a reliable note. */
|
|
15
|
+
insufficientData: boolean;
|
|
16
|
+
/** Completion checklist shown in the breakdown. */
|
|
17
|
+
completion: SupplierRatingCompletion;
|
|
18
|
+
};
|
|
19
|
+
export type SupplierRatingLabels = {
|
|
20
|
+
title: string;
|
|
21
|
+
/** Neutral state shown instead of a note when data is insufficient. */
|
|
22
|
+
insufficientData: string;
|
|
23
|
+
/** Section heading above the three weighted sub-scores. */
|
|
24
|
+
componentsTitle: string;
|
|
25
|
+
/** Section heading above the completion checklist. */
|
|
26
|
+
completionTitle: string;
|
|
27
|
+
/** Label for the "original response rate" reminder row. */
|
|
28
|
+
responseRate: string;
|
|
29
|
+
/** Suffix used for the "not enough data yet" sub-score value (e.g. "—"). */
|
|
30
|
+
notAvailable: string;
|
|
31
|
+
components: Record<SupplierRatingComponentKey, string>;
|
|
32
|
+
completion: Record<SupplierRatingCompletionKey, string>;
|
|
33
|
+
footer?: string;
|
|
34
|
+
};
|
|
35
|
+
export declare const DEFAULT_SUPPLIER_RATING_LABELS: SupplierRatingLabels;
|
|
36
|
+
/** Weights (in %) of each sub-score in the overall note. */
|
|
37
|
+
export declare const SUPPLIER_RATING_WEIGHTS: Record<SupplierRatingComponentKey, number>;
|
|
38
|
+
export declare function formatOverall(overall: number): string;
|
|
39
|
+
export declare function getHeadlineColor(overall: number): string;
|
|
40
|
+
type SupplierRatingBreakdownProps = {
|
|
41
|
+
rating: SupplierRating;
|
|
42
|
+
/** Optional original response rate (0..100) to remind in the breakdown. */
|
|
43
|
+
responseRate?: number;
|
|
44
|
+
labels?: Partial<SupplierRatingLabels>;
|
|
45
|
+
};
|
|
46
|
+
export declare const SupplierRatingBreakdown: ({ rating, responseRate, labels: labelsProp }: SupplierRatingBreakdownProps) => import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export {};
|