@propellerads/badge 7.0.0 → 8.0.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/index.js CHANGED
@@ -4,7 +4,7 @@ import { Children as n, createElement as r, isValidElement as i } from "react";
4
4
  import { clsx as a } from "clsx";
5
5
  import { cva as o } from "class-variance-authority";
6
6
  import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
7
- import './index.css';//#region src/cn.ts
7
+ import './index.css';// src/cn.ts
8
8
  var u = (...e) => a(e), d = {
9
9
  Fill: "fill",
10
10
  Outline: "outline",
@@ -54,7 +54,7 @@ var u = (...e) => a(e), d = {
54
54
  return !t || n.trim() === "" ? n : (t = !1, n.replace(/\S/, (e) => e.toUpperCase()));
55
55
  });
56
56
  }, _ = (e, t) => {
57
- if (!(e === void 0 && t === void 0)) return {
57
+ if (e !== void 0 || t !== void 0) return {
58
58
  ...e !== void 0 && { "--badge-bg": e },
59
59
  ...t !== void 0 && {
60
60
  "--badge-fg": t,
@@ -88,7 +88,6 @@ var u = (...e) => a(e), d = {
88
88
  }
89
89
  });
90
90
  };
91
- //#endregion
92
91
  export { m as BADGE_TYPE, y as Badge, y as default, f as BadgeTone, p as BadgeType, d as BadgeVariant, h as badgeVariants };
93
92
 
94
93
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/cn.ts","../src/types.ts","../src/variants.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the badge\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {useRender} from '@base-ui-components/react/use-render';\nimport type {ComponentType, CSSProperties, ReactNode} from 'react';\n\n/** The form: how the badge is drawn. It says nothing about colour. */\nexport const BadgeVariant = {\n /** The tone's pad, `-bg`, under the text. */\n Fill: 'fill',\n /** No pad: a dotted contour in the tone's colour, on whatever is behind the badge. */\n Outline: 'outline',\n /** The tone's colour itself as the pad, the text and icon on it in the page surface's colour. */\n Bright: 'bright',\n} as const;\nexport type BadgeVariant = (typeof BadgeVariant)[keyof typeof BadgeVariant];\n\n/**\n * The tone: what the badge says about the thing it stands next to. Each one is\n * a token triple — the `-bg` pad, the `-text` text, and the colour itself for\n * an icon and for the contour. Every form takes every tone.\n */\nexport const BadgeTone = {\n /** Something to know: the --color-action triple. */\n Info: 'info',\n /** Nothing is broken yet: the --color-warning triple. */\n Warning: 'warning',\n /** An error, or a state that cannot be taken back: the --color-danger triple. */\n Danger: 'danger',\n /** A scenario that worked: the --color-success triple. */\n Success: 'success',\n /** No status: a draft, an archive, an inactive item, on the grey --color-quiet triple. */\n Quiet: 'quiet',\n /** No status: a promo or a new feature, on the brand's --color-highlight triple. */\n Highlight: 'highlight',\n} as const;\nexport type BadgeTone = (typeof BadgeTone)[keyof typeof BadgeTone];\n\n/** @deprecated Use `BadgeTone`: the values are the same. */\nexport const BadgeType = BadgeTone;\n/** @deprecated Use `BadgeTone`. */\nexport type BadgeType = BadgeTone;\n\n/**\n * @deprecated Use `BadgeTone`. The enum v2 and v3 exported, with its\n * capitalised keys, kept so that code written against them still runs: 29 files\n * in seven products read `BADGE_TYPE.INFO` and the like.\n */\nexport const BADGE_TYPE = {\n INFO: BadgeTone.Info,\n WARNING: BadgeTone.Warning,\n DANGER: BadgeTone.Danger,\n SUCCESS: BadgeTone.Success,\n} as const;\n/** @deprecated Use `BadgeTone`. */\nexport type BADGE_TYPE = (typeof BADGE_TYPE)[keyof typeof BADGE_TYPE];\n\n/**\n * An icon from `@propellerads/icon`, as its component: `Star`, not `<Star />`.\n * The badge draws it, so an element — and a custom SVG with it — does not\n * compile.\n */\nexport type BadgeIcon = ComponentType<{color?: string}>;\n\n/**\n * The span's props without `style`: a badge's box is the system's, and of\n * everything in it a product may change only the colours, through `bgColor`\n * and `textColor`. `className` stays for placing the badge on the page.\n */\n/**\n * The form, and whether it is inverse. Only `fill` and `outline` turn over:\n * `bright` already has a pad of its own, so `variant=\"bright\"` with `inverse`\n * does not compile rather than compiling to nothing.\n */\ntype BadgeForm =\n | {\n /** How the badge is drawn. @default 'fill' */\n variant?: Exclude<BadgeVariant, typeof BadgeVariant.Bright>;\n /**\n * For a surface the design system does not control — a photo, a coloured\n * pad, a banner. Each form turns over in --color-light, which stays light\n * in both themes: `fill` takes it as its pad and keeps its text and icon\n * in the tone, `outline` stays without a pad and draws its contour, text\n * and icon in it.\n * @default false\n */\n inverse?: boolean;\n }\n | {\n /** How the badge is drawn. @default 'fill' */\n variant: typeof BadgeVariant.Bright;\n /** Not for `bright`: it already has a pad of its own. */\n inverse?: never;\n };\n\nexport type BadgeProps = Omit<useRender.ComponentProps<'span'>, 'style'> &\n BadgeForm & {\n /** Which colour that form is worn in. @default 'info' */\n tone?: BadgeTone;\n /**\n * The pad, in place of the tone's: a colour, or a gradient for a tier like\n * Platinum. For a look the design system does not have. An outline badge has\n * no pad and ignores it.\n */\n bgColor?: string;\n /**\n * The text and the icon — and an outline badge's contour — in place of the\n * tone's. Set it with `bgColor`, so the two stay legible together.\n */\n textColor?: string;\n /**\n * The icon before the text: one from `@propellerads/icon`, passed as its\n * component — `icon={Star}`. The badge draws it at 16px in the tone's\n * graphic colour.\n *\n * Pick it by weight as well as by meaning: a contour rather than a solid\n * shape (`CheckCircleOutline`, not `CheckCircle`), ink on no more than a\n * quarter of the 24-unit grid, two units clear of its edge, and not one with\n * its colour baked in (`LaughingSmile`, `SurveyOffer`, the brand logos).\n */\n icon?: BadgeIcon;\n /** The text, written in sentence case whatever case it is passed in. */\n children?: ReactNode;\n /** @deprecated Pass the text as children. */\n label?: ReactNode;\n /** @deprecated Use `tone`. */\n type?: BadgeType;\n /**\n * @deprecated Use `bgColor` and `textColor`. Only `background`,\n * `backgroundColor` and `color` are taken from it; everything else is ignored.\n */\n customStyle?: CSSProperties;\n };\n","import {cva} from 'class-variance-authority';\n\n/**\n * The class names the stylesheet defines. Form and tone are separate axes: the\n * variant decides where the colour goes, the tone which colour it is, so every\n * form can be worn in every tone.\n *\n * Exported so that markup which is not a badge can take its look:\n * `<span className={badgeVariants({variant: 'outline', tone: 'danger'})} />`.\n */\nconst badgeVariants = cva('badge', {\n variants: {\n variant: {\n fill: 'badge--fill',\n outline: 'badge--outline',\n bright: 'badge--bright',\n },\n tone: {\n info: 'badge--tone-info',\n warning: 'badge--tone-warning',\n danger: 'badge--tone-danger',\n success: 'badge--tone-success',\n quiet: 'badge--tone-quiet',\n highlight: 'badge--tone-highlight',\n },\n inverse: {\n true: 'badge--inverse',\n false: '',\n },\n },\n defaultVariants: {\n variant: 'fill',\n tone: 'info',\n inverse: false,\n },\n});\n\nexport {badgeVariants};\n","import {mergeProps} from '@base-ui-components/react/merge-props';\nimport {useRender} from '@base-ui-components/react/use-render';\nimport {Children, type CSSProperties, createElement, isValidElement, type ReactElement, type ReactNode} from 'react';\nimport './badge.css';\nimport {cn} from './cn';\nimport {BADGE_TYPE, type BadgeIcon, type BadgeProps, BadgeTone, BadgeType, BadgeVariant} from './types';\nimport {badgeVariants} from './variants';\n\n/**\n * Writes the text in sentence case — the first letter a capital, the rest small\n * — whatever case it arrived in: `NEW` and `new` both read `New`. CSS cannot do\n * it here: `::first-letter` does not apply to a flex container. Only the text\n * the badge is handed directly is rewritten; an element inside it keeps its own.\n */\nconst toSentenceCase = (children: ReactNode): ReactNode => {\n let isFirst = true;\n\n return Children.map(children, (child) => {\n if (typeof child !== 'string' && typeof child !== 'number') {\n return child;\n }\n\n const text = String(child).toLowerCase();\n\n if (!isFirst || text.trim() === '') {\n return text;\n }\n\n isFirst = false;\n\n return text.replace(/\\S/, (letter) => letter.toUpperCase());\n });\n};\n\n/**\n * The colours a product may change, as the custom properties the stylesheet\n * reads. The icon follows the text: a pad the system did not pick has no\n * graphic colour of its own to offer.\n */\nconst toColors = (bgColor: string | undefined, textColor: string | undefined): CSSProperties | undefined => {\n if (bgColor === undefined && textColor === undefined) {\n return undefined;\n }\n\n return {\n ...(bgColor !== undefined && {'--badge-bg': bgColor}),\n ...(textColor !== undefined && {'--badge-fg': textColor, '--badge-icon': textColor}),\n } as CSSProperties;\n};\n\n/**\n * The pack paints its icons black unless told otherwise, so the badge draws one\n * in `currentColor`, which it sets to the variant's graphic colour.\n *\n * v4 took the icon as an element, `icon={<Star color={Color.White} />}`. The\n * type no longer allows it, and a call that still passes one is drawn as it is\n * rather than broken.\n */\nconst renderIcon = (icon: BadgeIcon | ReactElement): ReactNode =>\n isValidElement(icon) ? icon : createElement(icon, {color: 'currentColor'});\n\n/*\n * shadcn's Badge on Base UI: a `<span>` by default, any element through\n * `render`, the form and the tone written out as `data-variant` and\n * `data-tone` next to `data-slot`.\n */\nconst Badge = ({\n className,\n variant = BadgeVariant.Fill,\n tone,\n inverse = false,\n bgColor,\n textColor,\n render,\n ref,\n label,\n type,\n icon,\n customStyle,\n children,\n ...props\n}: BadgeProps) => {\n const resolvedTone = tone ?? type ?? BadgeTone.Info;\n const colors = toColors(\n bgColor ?? (customStyle?.background as string | undefined) ?? customStyle?.backgroundColor,\n textColor ?? customStyle?.color,\n );\n\n return useRender({\n defaultTagName: 'span',\n render,\n ref,\n props: mergeProps<'span'>(\n {\n className: cn(\n badgeVariants({variant, tone: resolvedTone, inverse}),\n icon !== undefined && 'badge--icon',\n className,\n ),\n style: colors,\n children: (\n <>\n {icon !== undefined && (\n <span className=\"badge__icon\" aria-hidden>\n {renderIcon(icon)}\n </span>\n )}\n {toSentenceCase(children ?? label)}\n </>\n ),\n },\n props,\n ),\n state: {\n slot: 'badge',\n variant,\n tone: resolvedTone,\n inverse,\n },\n });\n};\n\nexport default Badge;\n\nexport type {BadgeIcon, BadgeProps};\nexport {BADGE_TYPE, Badge, BadgeTone, BadgeType, BadgeVariant, badgeVariants};\n"],"mappings":";;;;;;;AAOA,IAAM,KAAM,GAAG,MAA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AQ,KAAQ,EAAU,MACzC,IAAS,EACb,KAAY,GAAa,cAAqC,GAAa,iBAC3E,KAAa,GAAa,MAC3B;CAED,OAAO,EAAU;EACf,gBAAgB;EAChB;EACA;EACA,OAAO,EACL;GACE,WAAW,EACT,EAAc;IAAC;IAAS,MAAM;IAAc;IAAQ,CAAC,EACrD,MAAS,KAAA,KAAa,eACtB,EACD;GACD,OAAO;GACP,UACE,kBAAA,GAAA,EAAA,UAAA,CACG,MAAS,KAAA,KACR,kBAAC,QAAD;IAAM,WAAU;IAAc,eAAA;cAC3B,EAAW,EAAK;IACZ,CAAA,EAER,EAAe,KAAY,EAAM,CACjC,EAAA,CAAA;GAEN,EACD,EACD;EACD,OAAO;GACL,MAAM;GACN;GACA,MAAM;GACN;GACD;EACF,CAAC"}
1
+ {"version":3,"file":"index.js","names":["_Fragment","cn","inputs","clsx","BadgeVariant","BadgeTone","BadgeType","BADGE_TYPE","badgeVariants","cva","toSentenceCase","isFirst","Children","children","child","text","letter","toColors","bgColor","textColor","renderIcon","isValidElement","icon","createElement","Badge","props","resolvedTone","tone","type","colors","customStyle","useRender","mergeProps","className","Fragment","label"],"sources":["../src/cn.ts","../src/types.ts","../src/variants.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the badge\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {useRender} from '@base-ui-components/react/use-render';\nimport type {ComponentType, CSSProperties, ReactNode} from 'react';\n\n/** The form: how the badge is drawn. It says nothing about colour. */\nexport const BadgeVariant = {\n /** The tone's pad, `-bg`, under the text. */\n Fill: 'fill',\n /** No pad: a dotted contour in the tone's colour, on whatever is behind the badge. */\n Outline: 'outline',\n /** The tone's colour itself as the pad, the text and icon on it in the page surface's colour. */\n Bright: 'bright',\n} as const;\nexport type BadgeVariant = (typeof BadgeVariant)[keyof typeof BadgeVariant];\n\n/**\n * The tone: what the badge says about the thing it stands next to. Each one is\n * a token triple — the `-bg` pad, the `-text` text, and the colour itself for\n * an icon and for the contour. Every form takes every tone.\n */\nexport const BadgeTone = {\n /** Something to know: the --color-action triple. */\n Info: 'info',\n /** Nothing is broken yet: the --color-warning triple. */\n Warning: 'warning',\n /** An error, or a state that cannot be taken back: the --color-danger triple. */\n Danger: 'danger',\n /** A scenario that worked: the --color-success triple. */\n Success: 'success',\n /** No status: a draft, an archive, an inactive item, on the grey --color-quiet triple. */\n Quiet: 'quiet',\n /** No status: a promo or a new feature, on the brand's --color-highlight triple. */\n Highlight: 'highlight',\n} as const;\nexport type BadgeTone = (typeof BadgeTone)[keyof typeof BadgeTone];\n\n/** @deprecated Use `BadgeTone`: the values are the same. */\nexport const BadgeType = BadgeTone;\n/** @deprecated Use `BadgeTone`. */\nexport type BadgeType = BadgeTone;\n\n/**\n * @deprecated Use `BadgeTone`. The enum v2 and v3 exported, with its\n * capitalised keys, kept so that code written against them still runs: 29 files\n * in seven products read `BADGE_TYPE.INFO` and the like.\n */\nexport const BADGE_TYPE = {\n INFO: BadgeTone.Info,\n WARNING: BadgeTone.Warning,\n DANGER: BadgeTone.Danger,\n SUCCESS: BadgeTone.Success,\n} as const;\n/** @deprecated Use `BadgeTone`. */\nexport type BADGE_TYPE = (typeof BADGE_TYPE)[keyof typeof BADGE_TYPE];\n\n/**\n * An icon from `@propellerads/icon`, as its component: `Star`, not `<Star />`.\n * The badge draws it, so an element — and a custom SVG with it — does not\n * compile.\n */\nexport type BadgeIcon = ComponentType<{color?: string}>;\n\n/**\n * The span's props without `style`: a badge's box is the system's, and of\n * everything in it a product may change only the colours, through `bgColor`\n * and `textColor`. `className` stays for placing the badge on the page.\n */\n/**\n * The form, and whether it is inverse. Only `fill` and `outline` turn over:\n * `bright` already has a pad of its own, so `variant=\"bright\"` with `inverse`\n * does not compile rather than compiling to nothing.\n */\ntype BadgeForm =\n | {\n /** How the badge is drawn. @default 'fill' */\n variant?: Exclude<BadgeVariant, typeof BadgeVariant.Bright>;\n /**\n * For a surface the design system does not control — a photo, a coloured\n * pad, a banner. Each form turns over in --color-light, which stays light\n * in both themes: `fill` takes it as its pad and keeps its text and icon\n * in the tone, `outline` stays without a pad and draws its contour, text\n * and icon in it.\n * @default false\n */\n inverse?: boolean;\n }\n | {\n /** How the badge is drawn. @default 'fill' */\n variant: typeof BadgeVariant.Bright;\n /** Not for `bright`: it already has a pad of its own. */\n inverse?: never;\n };\n\nexport type BadgeProps = Omit<useRender.ComponentProps<'span'>, 'style'> &\n BadgeForm & {\n /** Which colour that form is worn in. @default 'info' */\n tone?: BadgeTone;\n /**\n * The pad, in place of the tone's: a colour, or a gradient for a tier like\n * Platinum. For a look the design system does not have. An outline badge has\n * no pad and ignores it.\n */\n bgColor?: string;\n /**\n * The text and the icon — and an outline badge's contour — in place of the\n * tone's. Set it with `bgColor`, so the two stay legible together.\n */\n textColor?: string;\n /**\n * The icon before the text: one from `@propellerads/icon`, passed as its\n * component — `icon={Star}`. The badge draws it at 16px in the tone's\n * graphic colour.\n *\n * Pick it by weight as well as by meaning: a contour rather than a solid\n * shape (`CheckCircleOutline`, not `CheckCircle`), ink on no more than a\n * quarter of the 24-unit grid, two units clear of its edge, and not one with\n * its colour baked in (`LaughingSmile`, `SurveyOffer`, the brand logos).\n */\n icon?: BadgeIcon;\n /** The text, written in sentence case whatever case it is passed in. */\n children?: ReactNode;\n /** @deprecated Pass the text as children. */\n label?: ReactNode;\n /** @deprecated Use `tone`. */\n type?: BadgeType;\n /**\n * @deprecated Use `bgColor` and `textColor`. Only `background`,\n * `backgroundColor` and `color` are taken from it; everything else is ignored.\n */\n customStyle?: CSSProperties;\n };\n","import {cva} from 'class-variance-authority';\n\n/**\n * The class names the stylesheet defines. Form and tone are separate axes: the\n * variant decides where the colour goes, the tone which colour it is, so every\n * form can be worn in every tone.\n *\n * Exported so that markup which is not a badge can take its look:\n * `<span className={badgeVariants({variant: 'outline', tone: 'danger'})} />`.\n */\nconst badgeVariants = cva('badge', {\n variants: {\n variant: {\n fill: 'badge--fill',\n outline: 'badge--outline',\n bright: 'badge--bright',\n },\n tone: {\n info: 'badge--tone-info',\n warning: 'badge--tone-warning',\n danger: 'badge--tone-danger',\n success: 'badge--tone-success',\n quiet: 'badge--tone-quiet',\n highlight: 'badge--tone-highlight',\n },\n inverse: {\n true: 'badge--inverse',\n false: '',\n },\n },\n defaultVariants: {\n variant: 'fill',\n tone: 'info',\n inverse: false,\n },\n});\n\nexport {badgeVariants};\n","import {mergeProps} from '@base-ui-components/react/merge-props';\nimport {useRender} from '@base-ui-components/react/use-render';\nimport {Children, type CSSProperties, createElement, isValidElement, type ReactElement, type ReactNode} from 'react';\nimport './badge.css';\nimport {cn} from './cn';\nimport {BADGE_TYPE, type BadgeIcon, type BadgeProps, BadgeTone, BadgeType, BadgeVariant} from './types';\nimport {badgeVariants} from './variants';\n\n/**\n * Writes the text in sentence case — the first letter a capital, the rest small\n * — whatever case it arrived in: `NEW` and `new` both read `New`. CSS cannot do\n * it here: `::first-letter` does not apply to a flex container. Only the text\n * the badge is handed directly is rewritten; an element inside it keeps its own.\n */\nconst toSentenceCase = (children: ReactNode): ReactNode => {\n let isFirst = true;\n\n return Children.map(children, (child) => {\n if (typeof child !== 'string' && typeof child !== 'number') {\n return child;\n }\n\n const text = String(child).toLowerCase();\n\n if (!isFirst || text.trim() === '') {\n return text;\n }\n\n isFirst = false;\n\n return text.replace(/\\S/, (letter) => letter.toUpperCase());\n });\n};\n\n/**\n * The colours a product may change, as the custom properties the stylesheet\n * reads. The icon follows the text: a pad the system did not pick has no\n * graphic colour of its own to offer.\n */\nconst toColors = (bgColor: string | undefined, textColor: string | undefined): CSSProperties | undefined => {\n if (bgColor === undefined && textColor === undefined) {\n return undefined;\n }\n\n return {\n ...(bgColor !== undefined && {'--badge-bg': bgColor}),\n ...(textColor !== undefined && {'--badge-fg': textColor, '--badge-icon': textColor}),\n } as CSSProperties;\n};\n\n/**\n * The pack paints its icons black unless told otherwise, so the badge draws one\n * in `currentColor`, which it sets to the variant's graphic colour.\n *\n * v4 took the icon as an element, `icon={<Star color={Color.White} />}`. The\n * type no longer allows it, and a call that still passes one is drawn as it is\n * rather than broken.\n */\nconst renderIcon = (icon: BadgeIcon | ReactElement): ReactNode =>\n isValidElement(icon) ? icon : createElement(icon, {color: 'currentColor'});\n\n/*\n * shadcn's Badge on Base UI: a `<span>` by default, any element through\n * `render`, the form and the tone written out as `data-variant` and\n * `data-tone` next to `data-slot`.\n */\nconst Badge = ({\n className,\n variant = BadgeVariant.Fill,\n tone,\n inverse = false,\n bgColor,\n textColor,\n render,\n ref,\n label,\n type,\n icon,\n customStyle,\n children,\n ...props\n}: BadgeProps) => {\n const resolvedTone = tone ?? type ?? BadgeTone.Info;\n const colors = toColors(\n bgColor ?? (customStyle?.background as string | undefined) ?? customStyle?.backgroundColor,\n textColor ?? customStyle?.color,\n );\n\n return useRender({\n defaultTagName: 'span',\n render,\n ref,\n props: mergeProps<'span'>(\n {\n className: cn(\n badgeVariants({variant, tone: resolvedTone, inverse}),\n icon !== undefined && 'badge--icon',\n className,\n ),\n style: colors,\n children: (\n <>\n {icon !== undefined && (\n <span className=\"badge__icon\" aria-hidden>\n {renderIcon(icon)}\n </span>\n )}\n {toSentenceCase(children ?? label)}\n </>\n ),\n },\n props,\n ),\n state: {\n slot: 'badge',\n variant,\n tone: resolvedTone,\n inverse,\n },\n });\n};\n\nexport default Badge;\n\nexport type {BadgeIcon, BadgeProps};\nexport {BADGE_TYPE, Badge, BadgeTone, BadgeType, BadgeVariant, badgeVariants};\n"],"mappings":";;;;;;;AAOA,IAAMC,KAAM,GAAGC,MAAiCC,EAAKD,CAAM,GCH9CE,IAAe;CAE1B,MAAM;CAEN,SAAS;CAET,QAAQ;AACV,GAQaC,IAAY;CAEvB,MAAM;CAEN,SAAS;CAET,QAAQ;CAER,SAAS;CAET,OAAO;CAEP,WAAW;AACb,GAIaC,IAAYD,G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OAAOC,EAAU;EACf,gBAAgB;EAChB;EACA;EACA,OAAOC,EACL;GACE,WAAW/B,EACTO,EAAc;IAAC;IAAS,MAAMkB;IAAc;GAAO,CAAC,GACpDJ,MAAS,KAAA,KAAa,eACtBW,CACF;GACA,OAAOJ;GACP,UACE,kBAAA7B,GAAA,EAAA,UAAA,CACGsB,MAAS,KAAA,KACR,kBAAC,QAAD;IAAM,WAAU;IAAc,eAAA;IAC3B,UAAAF,EAAWE,CAAI;GACZ,CAAA,GAEPZ,EAAeG,KAAYsB,CAAK,CACjC,EAAA,CAAA;EAEN,GACAV,CACF;EACA,OAAO;GACL,MAAM;GACN;GACA,MAAMC;GACN;EACF;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@propellerads/badge",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/index.css",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/propellerads/ui-components/issues"
25
25
  },
26
26
  "scripts": {
27
- "build": "tsc && vite build && bunx rollup -c rollup.dts.config.mjs"
27
+ "build": "tsc && vite build && rollup -c rollup.dts.config.mjs"
28
28
  },
29
29
  "homepage": "https://github.com/propellerads/ui-components#readme",
30
30
  "private": false,
@@ -34,7 +34,7 @@
34
34
  "clsx": "^2.1.1"
35
35
  },
36
36
  "peerDependencies": {
37
- "@propellerads/tokens": ">=0.4.0",
37
+ "@propellerads/tokens": ">=0.5.0",
38
38
  "react": "^18.0.0 || ^19.0.0",
39
39
  "react-dom": "^18.0.0 || ^19.0.0"
40
40
  },