@allxsmith/bestax-bulma 5.35.0 → 5.35.1
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.
|
@@ -105,8 +105,7 @@ function getIconClasses(library, name, variant, features) {
|
|
|
105
105
|
*/
|
|
106
106
|
const Icon = ({ className, textColor, bgColor, name, library, variant, features, libraryFeatures, // Deprecated but maintained for backward compatibility
|
|
107
107
|
size, ariaLabel, style, icon, // Capture and exclude the deprecated 'icon' prop from DOM
|
|
108
|
-
color
|
|
109
|
-
containerClassName, children, ...restProps }) => {
|
|
108
|
+
color, containerClassName, children, ...restProps }) => {
|
|
110
109
|
// Get the default icon library from context, fallback to 'fa' if not set
|
|
111
110
|
const defaultLibrary = useIconLibrary();
|
|
112
111
|
/**
|
|
@@ -114,7 +113,7 @@ containerClassName, children, ...restProps }) => {
|
|
|
114
113
|
* Note: variant, features, and libraryFeatures are excluded from props spread
|
|
115
114
|
*/
|
|
116
115
|
const { bulmaHelperClasses, rest } = useBulmaClasses({
|
|
117
|
-
color: textColor,
|
|
116
|
+
color: textColor ?? color,
|
|
118
117
|
backgroundColor: bgColor,
|
|
119
118
|
...restProps,
|
|
120
119
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","sources":["../../../src/elements/Icon.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\nimport { useIconLibrary } from '../helpers/Config';\n\n// TypeScript declaration for Ionicons web component\ninterface IonIconProps extends React.HTMLAttributes<HTMLElement> {\n name?: string;\n src?: string;\n icon?: unknown;\n size?: string;\n lazy?: boolean;\n sanitize?: boolean;\n color?: string;\n flipRtl?: boolean;\n ariaLabel?: string;\n ariaHidden?: string;\n}\n\n// React 19 moved the global `JSX` namespace under the `react` module, so the\n// `<ion-icon>` web-component augmentation must target `React.JSX` to take effect.\ndeclare module 'react' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'ion-icon': IonIconProps;\n }\n }\n}\n\ntype IconLibrary = 'fa' | 'mdi' | 'ion' | 'material-icons' | 'material-symbols'; // 'fa' = Font Awesome, 'mdi' = Material Design Icons, 'ion' = Ionicons Web Components, 'material-icons' = Google Material Icons, 'material-symbols' = Google Material Symbols\n\n/**\n * Shared props for the Icon component, independent of whether a class-based `name` or a\n * custom `children` node supplies the glyph.\n */\ninterface IconBaseProps\n extends React.HTMLAttributes<HTMLSpanElement>, BulmaClassesProps {\n /** Additional CSS classes to apply. */\n className?: string;\n /** Text color helper. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /** Bulma color modifier for the icon. */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Background color helper. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /**\n * Legacy icon class string (e.g. `'fas fa-star'`). Only its last segment is read, as the\n * glyph name; the library still comes from `library` or `ConfigProvider`, so\n * `'mdi mdi-rocket'` renders an `fa` class unless the effective library is already `mdi` —\n * set it here or on the provider.\n *\n * @deprecated Use `name` instead.\n */\n icon?: string;\n /**\n * The icon library to use ('fa' = Font Awesome, 'mdi' = Material Design Icons, 'ion' = Ionicons Web Components, 'material-icons' = Google Material Icons, 'material-symbols' = Google Material Symbols). Defaults to the value set in ConfigProvider or 'fa' if not configured. Ignored when `children` supplies the glyph instead of `name`.\n * @defaultValue 'fa'\n */\n library?: IconLibrary; // defaults to ConfigProvider iconLibrary or 'fa'\n /** Icon style variant (e.g. `'solid'`, `'outlined'`, `'rounded'`). Ignored when `children` supplies the glyph instead of `name`. */\n variant?: string; // e.g., 'solid', 'outlined', 'rounded', 'sharp'\n /** Additional modifiers (e.g. `'fa-lg'`, `'fa-spin'`, `'is-size-1'`). Ignored when `children` supplies the glyph instead of `name`. */\n features?: string | string[]; // e.g., 'fa-lg', 'fa-spin', 'is-size-1'\n /**\n * Additional modifiers in the older combined form, parsed into `variant` and `features`.\n *\n * @deprecated Use `variant` and `features` instead.\n */\n libraryFeatures?: string | string[];\n /** Size modifier for the icon container. */\n size?: 'small' | 'medium' | 'large';\n /**\n * Accessible name for an icon that means something on its own. Set it and the container\n * span gets `role=\"img\"` with this `aria-label`, so the name is exactly this text: a\n * Material ligature such as `rocket_launch` inside stays out of it. Leave it unset (or\n * empty) and the icon is decorative: the span renders `aria-hidden=\"true\"` and no name,\n * so it adds nothing to the accessible name of a `Button` or text around it. For an\n * icon-only control, put the name on the control (e.g. `Button`'s `aria-label`) and leave\n * this unset. A non-empty native `aria-label` or `aria-labelledby` passed instead also\n * counts as a name, and an explicit `role` or `aria-hidden` wins over both defaults. An\n * unnamed icon given a `role` or a `tabIndex` of its own isn't hidden, since hiding\n * something focusable is a failure of its own.\n */\n ariaLabel?: string;\n /** Inline style object. */\n style?: React.CSSProperties;\n /** Override the default `'icon'` container class (e.g., `'panel-icon'`). */\n containerClassName?: string; // Override the default 'icon' container class (e.g., 'panel-icon')\n}\n\n/**\n * Props for `Icon` rendering a class-based glyph from an icon library.\n */\nexport interface IconNameProps extends IconBaseProps {\n /** The icon name, with or without its library prefix (e.g. `'star'` or `'fa-star'`). Mutually exclusive with `children`. */\n name: string; // e.g., 'star', 'account', 'home-outline'\n /** A custom node (an inline SVG, a `react-icons` component, …) rendered inside the icon container in place of a class-based glyph. Mutually exclusive with `name`. */\n children?: never;\n}\n\n/**\n * Props for `Icon` rendering a custom node (an inline SVG, a `react-icons` component, a Font\n * Awesome React `<FontAwesomeIcon>`, …) in place of a class-based glyph.\n */\nexport interface IconChildrenProps extends IconBaseProps {\n /** The icon name, with or without its library prefix (e.g. `'star'` or `'fa-star'`). Mutually exclusive with `children`. */\n name?: undefined;\n /** A custom node (an inline SVG, a `react-icons` component, …) rendered inside the icon container in place of a class-based glyph. Mutually exclusive with `name`. */\n // `undefined` is excluded deliberately: the renderer discriminates on `children !== undefined`,\n // so `children={undefined}` would satisfy the type but fall through to the `name` path with no\n // name and render an `fa-undefined` glyph. Excluding it keeps the advertised\n // exactly-one-of-`name`-or-`children` constraint matching what actually renders.\n children: Exclude<React.ReactNode, undefined>;\n}\n\n/**\n * Props for `Icon` naming its glyph through the deprecated `icon` prop instead of `name`.\n *\n * The runtime has always accepted `icon` on its own — it strips a leading library prefix off\n * the class string and falls through to the `name` path — but the type offered no member without\n * a `name` or `children`, so every caller still on the deprecated prop got an error the\n * package could not see — until #663 nothing here type-checked a test or a story, so the\n * three `Icon.test.tsx` cases exercising this path proved the runtime and said nothing about\n * the type. Declaring the path is the honest resolution: it is deprecated, not removed, and a\n * deprecation that does not type-check is a removal announced only to whoever tries it.\n *\n * @deprecated Pass `name` instead. This member goes when `icon` does.\n */\nexport interface IconDeprecatedProps extends IconBaseProps {\n /**\n * Legacy icon class string (e.g. `'fas fa-star'`). Only its last segment is read, as the\n * glyph name; the library still comes from `library` or `ConfigProvider`, so\n * `'mdi mdi-rocket'` renders an `fa` class unless the effective library is already `mdi` —\n * set it here or on the provider.\n *\n * @deprecated Use `name` instead.\n */\n // Required here, optional on `IconBaseProps`: the other two members allow it\n // alongside `name`, and this one is the member where it IS the glyph. Same\n // prose in both places on purpose — the API-docs extractor reads whichever it\n // reaches first, and the two must not drift apart.\n icon: string;\n /** The icon name. Absent on this path — `icon` supplies the glyph. */\n name?: undefined;\n /** A custom node. Mutually exclusive with `icon`. */\n children?: never;\n}\n\n/**\n * Props for the Icon component — a discriminated union of a class-based `name`, a custom\n * `children` node, and the deprecated `icon` class string.\n */\nexport type IconProps = IconNameProps | IconChildrenProps | IconDeprecatedProps;\n\n/**\n * Strips a redundant leading library prefix from an icon name (e.g. `fa-check` -> `check`\n * for the `fa` library, `mdi-account` -> `account` for `mdi`), so `name` behaves the same\n * whether or not the caller includes the prefix. Font Awesome and Material Design Icons docs\n * conventionally refer to icons with their class prefix (`fa-check`), which otherwise gets\n * doubled by `getIconClasses` (producing `fa-fa-check`, matching no glyph).\n *\n * @param {string} name - The icon name, possibly including a redundant library prefix.\n * @param {IconLibrary} library - The icon library the name will be rendered with.\n * @returns {string} The icon name with any redundant leading library prefix removed.\n */\nfunction stripRedundantLibraryPrefix(\n name: string,\n library: IconLibrary\n): string {\n if (!name) {\n return name;\n }\n if (library === 'fa' && name.startsWith('fa-')) {\n return name.substring(3);\n }\n if (library === 'mdi' && name.startsWith('mdi-')) {\n return name.substring(4);\n }\n return name;\n}\n\n/**\n * Gets the correct classes for the icon element based on the library and features.\n *\n * @param {IconLibrary} library - The icon library.\n * @param {string} name - The icon name.\n * @param {string} [variant] - Icon style variant (e.g., 'solid', 'outlined', 'rounded').\n * @param {string | string[]} [features] - Additional library-specific modifiers.\n * @returns {string} The combined class string for the icon.\n */\nfunction getIconClasses(\n library: IconLibrary,\n name: string,\n variant?: string,\n features?: string | string[]\n): string {\n let baseClass: string;\n let iconClass: string;\n const featureList = Array.isArray(features)\n ? features\n : features\n ? [features]\n : [];\n\n switch (library) {\n case 'fa': {\n // Font Awesome: use variant as style ('solid' -> 'fas', 'regular' -> 'far', etc.)\n const styleMap: Record<string, string> = {\n solid: 'fas',\n regular: 'far',\n brands: 'fab',\n light: 'fal',\n duotone: 'fad',\n thin: 'fat',\n };\n const faStyle = variant ? styleMap[variant] || variant : 'fas';\n baseClass = faStyle;\n iconClass = `fa-${name}`;\n return [baseClass, iconClass, ...featureList].join(' ');\n }\n case 'mdi':\n // Material Design Icons: no variants, just features\n baseClass = 'mdi';\n iconClass = `mdi-${name}`;\n return [baseClass, iconClass, ...featureList].join(' ');\n case 'material-icons': {\n // Google Material Icons: map variants to full class names\n const styleVariants: Record<string, string> = {\n filled: 'material-icons',\n outlined: 'material-icons-outlined',\n round: 'material-icons-round',\n sharp: 'material-icons-sharp',\n };\n baseClass = variant\n ? styleVariants[variant] || `material-icons-${variant}`\n : 'material-icons';\n return [baseClass, ...featureList].join(' ');\n }\n case 'material-symbols': {\n // Google Material Symbols: map variants to full class names\n const styleVariants: Record<string, string> = {\n outlined: 'material-symbols-outlined',\n rounded: 'material-symbols-rounded',\n sharp: 'material-symbols-sharp',\n };\n baseClass = variant\n ? styleVariants[variant] || `material-symbols-${variant}`\n : 'material-symbols-outlined';\n return [baseClass, ...featureList].join(' ');\n }\n default:\n // fallback: just icon name and features\n return [name, ...featureList].join(' ');\n }\n}\n\n/**\n * The `Icon` component is a Bulma-styled wrapper for displaying icons from various libraries (Font Awesome, Material Design Icons, Ionicons, Google Material Icons, Material Symbols, etc.).\n *\n * @function\n * @param {IconProps} props - Props for the Icon component.\n * @returns {JSX.Element} The rendered icon element.\n * @see {@link https://bulma.io/documentation/elements/icon/ | Bulma Icon documentation}\n */\nexport const Icon: React.FC<IconProps> = ({\n className,\n textColor,\n bgColor,\n name,\n library,\n variant,\n features,\n libraryFeatures, // Deprecated but maintained for backward compatibility\n size,\n ariaLabel,\n style,\n icon, // Capture and exclude the deprecated 'icon' prop from DOM\n color: _color, // Exclude 'color' prop if passed directly\n containerClassName,\n children,\n ...restProps\n}) => {\n // Get the default icon library from context, fallback to 'fa' if not set\n const defaultLibrary = useIconLibrary();\n\n /**\n * Generates Bulma helper classes and separates out remaining props.\n * Note: variant, features, and libraryFeatures are excluded from props spread\n */\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor,\n backgroundColor: bgColor,\n ...restProps,\n });\n\n // Hoisted unconditionally to respect rules-of-hooks; the branches below\n // pick which result to consume.\n const defaultIconClasses = usePrefixedClassNames('icon', {\n [`is-${size}`]: size,\n });\n const sizeModifierClass = usePrefixedClassNames(\n size ? `is-${size}` : undefined\n );\n\n const bulmaClasses = containerClassName\n ? containerClassName\n : defaultIconClasses;\n\n const iconContainerClasses = classNames(\n bulmaClasses,\n containerClassName && size ? sizeModifierClass : undefined,\n bulmaHelperClasses,\n className\n );\n\n // A named icon is an image, whose name is its label alone, so a ligature inside\n // never leaks into it. An unnamed one is decorative and hidden outright. Spread\n // before `rest`, so a caller's own `role` or `aria-hidden` still wins.\n const named =\n !!ariaLabel || !!restProps['aria-label'] || !!restProps['aria-labelledby'];\n // A caller's own `role` or `tabIndex` on an unnamed icon means it isn't decoration (an\n // icon made a button, say), so it isn't hidden either: `aria-hidden` on something\n // focusable is a failure of its own.\n const a11yProps = named\n ? { role: 'img', 'aria-label': ariaLabel || undefined }\n : restProps.role !== undefined || restProps.tabIndex !== undefined\n ? {}\n : { 'aria-hidden': true };\n\n if (children !== undefined) {\n // `IconChildrenProps`: render the caller's node (an inline SVG, a `react-icons`\n // component, …) in place of a class-based glyph. Library/variant/features don't apply.\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n {children}\n </span>\n );\n }\n\n // `name` is guaranteed once `children` is absent UNLESS the caller is on the deprecated\n // `icon` path, which `IconDeprecatedProps` declares with `name?: undefined`.\n // (`IconChildrenProps['children']` excludes `undefined`, so `children={undefined}` can't\n // slip past into this branch.) The cast covers that third member, and the `!name && icon`\n // fallback below is what fills it in.\n let finalName = name as string;\n if (!name && icon) {\n // If icon prop is provided instead of name, try to parse it\n // e.g., \"mdi mdi-rocket-launch\" -> \"rocket-launch\"\n if (typeof icon === 'string') {\n const parts = icon.split(' ');\n const lastPart = parts[parts.length - 1];\n if (lastPart.startsWith('mdi-')) {\n finalName = lastPart.substring(4); // Remove \"mdi-\" prefix\n } else if (lastPart.startsWith('fa-')) {\n finalName = lastPart.substring(3); // Remove \"fa-\" prefix\n } else {\n finalName = lastPart;\n }\n }\n }\n\n const finalLibrary = library || defaultLibrary || 'fa';\n\n // Normalize a redundant leading library prefix (e.g. \"fa-check\" -> \"check\" when the\n // library is 'fa'), so `name` behaves identically with or without the prefix.\n finalName = stripRedundantLibraryPrefix(finalName, finalLibrary);\n\n if (!finalName) {\n // No glyph to name. Reachable through the public type only as `icon=\"\"`, and otherwise\n // by a plain-JS caller (or one that casts). Building a class off an absent name produced\n // a bogus `fa-undefined` glyph; render the bare container instead, matching the\n // `children` branch.\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n />\n );\n }\n\n // Backward compatibility: if libraryFeatures is provided, parse it for variant and features\n let finalVariant = variant;\n let finalFeatures = features;\n\n if (libraryFeatures && !variant && !features) {\n const legacyFeatures = Array.isArray(libraryFeatures)\n ? libraryFeatures\n : [libraryFeatures];\n\n // For Font Awesome, extract style from features\n if (finalLibrary === 'fa') {\n const faStyle = legacyFeatures.find(f =>\n [\n 'fas',\n 'far',\n 'fab',\n 'fal',\n 'fad',\n 'fat',\n 'solid',\n 'regular',\n 'brands',\n 'light',\n 'duotone',\n 'thin',\n ].includes(f)\n );\n if (faStyle) {\n finalVariant = faStyle;\n finalFeatures = legacyFeatures.filter(f => f !== faStyle);\n } else {\n finalFeatures = legacyFeatures;\n }\n }\n // For Material Icons/Symbols, extract style variant\n else if (\n finalLibrary === 'material-icons' ||\n finalLibrary === 'material-symbols'\n ) {\n const styleVariants =\n finalLibrary === 'material-icons'\n ? ['filled', 'outlined', 'round', 'sharp']\n : ['outlined', 'rounded', 'sharp'];\n\n const styleVariant = legacyFeatures.find(f => styleVariants.includes(f));\n if (styleVariant) {\n finalVariant = styleVariant;\n finalFeatures = legacyFeatures.filter(f => f !== styleVariant);\n } else {\n finalFeatures = legacyFeatures;\n }\n }\n // For others, all features go to finalFeatures\n else {\n finalFeatures = legacyFeatures;\n }\n }\n\n // Handle web components vs CSS-based icons\n if (finalLibrary === 'ion') {\n // For Ionicons, handle variant in the name\n let ionName = finalName;\n if (finalVariant === 'outline') {\n ionName = `${finalName}-outline`;\n } else if (finalVariant === 'sharp') {\n ionName = `${finalName}-sharp`;\n }\n\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n <ion-icon name={ionName} />\n </span>\n );\n }\n\n // Legacy CSS-based icons\n const iClasses = getIconClasses(\n finalLibrary,\n finalName,\n finalVariant,\n finalFeatures\n );\n\n // Material Icons and Material Symbols use text content, not CSS classes for the icon name\n if (\n finalLibrary === 'material-icons' ||\n finalLibrary === 'material-symbols'\n ) {\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n <i className={iClasses}>{finalName}</i>\n </span>\n );\n }\n\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n <i className={iClasses} />\n </span>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;AA+JA;;;;;;;;;;AAUG;AACH,SAAS,2BAA2B,CAClC,IAAY,EACZ,OAAoB,EAAA;IAEpB,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI;IACb;IACA,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;AAC9C,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1B;IACA,IAAI,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;AAChD,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1B;AACA,IAAA,OAAO,IAAI;AACb;AAEA;;;;;;;;AAQG;AACH,SAAS,cAAc,CACrB,OAAoB,EACpB,IAAY,EACZ,OAAgB,EAChB,QAA4B,EAAA;AAE5B,IAAA,IAAI,SAAiB;AACrB,IAAA,IAAI,SAAiB;AACrB,IAAA,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ;AACxC,UAAE;AACF,UAAE;cACE,CAAC,QAAQ;cACT,EAAE;IAER,QAAQ,OAAO;QACb,KAAK,IAAI,EAAE;;AAET,YAAA,MAAM,QAAQ,GAA2B;AACvC,gBAAA,KAAK,EAAE,KAAK;AACZ,gBAAA,OAAO,EAAE,KAAK;AACd,gBAAA,MAAM,EAAE,KAAK;AACb,gBAAA,KAAK,EAAE,KAAK;AACZ,gBAAA,OAAO,EAAE,KAAK;AACd,gBAAA,IAAI,EAAE,KAAK;aACZ;AACD,YAAA,MAAM,OAAO,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GA,IAAA,IAAI,YAAY,KAAK,KAAK,EAAE;;QAE1B,IAAI,OAAO,GAAG,SAAS;AACvB,QAAA,IAAI,YAAY,KAAK,SAAS,EAAE;AAC9B,YAAA,OAAO,GAAG,CAAA,EAAG,SAAS,CAAA,QAAA,CAAU;QAClC;AAAO,aAAA,IAAI,YAAY,KAAK,OAAO,EAAE;AACnC,YAAA,OAAO,GAAG,CAAA,EAAG,SAAS,CAAA,MAAA,CAAQ;QAChC;QAEA,QACEA,cACE,SAAS,EAAE,oBAAoB,EAAA,GAC3B,SAAS,EACb,KAAK,EAAE,KAAK,EAAA,GACR,IAAI,YAERA,GAAA,CAAA,UAAA,EAAA,EAAU,IAAI,EAAE,OAAO,EAAA,CAAI,EAAA,CACtB;IAEX;;AAGA,IAAA,MAAM,QAAQ,GAAG,cAAc,CAC7B,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,aAAa,CACd;;IAGD,IACE,YAAY,KAAK,gBAAgB;QACjC,YAAY,KAAK,kBAAkB,EACnC;QACA,QACEA,cACE,SAAS,EAAE,oBAAoB,EAAA,GAC3B,SAAS,EACb,KAAK,EAAE,KAAK,KACR,IAAI,EAAA,QAAA,EAERA,GAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAE,QAAQ,YAAG,SAAS,EAAA,CAAK,EAAA,CAClC;IAEX;IAEA,QACEA,cACE,SAAS,EAAE,oBAAoB,EAAA,GAC3B,SAAS,EACb,KAAK,EAAE,KAAK,EAAA,GACR,IAAI,YAERA,GAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAE,QAAQ,EAAA,CAAI,EAAA,CACrB;AAEX;;"}
|
|
1
|
+
{"version":3,"file":"Icon.js","sources":["../../../src/elements/Icon.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\nimport { useIconLibrary } from '../helpers/Config';\n\n// TypeScript declaration for Ionicons web component\ninterface IonIconProps extends React.HTMLAttributes<HTMLElement> {\n name?: string;\n src?: string;\n icon?: unknown;\n size?: string;\n lazy?: boolean;\n sanitize?: boolean;\n color?: string;\n flipRtl?: boolean;\n ariaLabel?: string;\n ariaHidden?: string;\n}\n\n// React 19 moved the global `JSX` namespace under the `react` module, so the\n// `<ion-icon>` web-component augmentation must target `React.JSX` to take effect.\ndeclare module 'react' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'ion-icon': IonIconProps;\n }\n }\n}\n\ntype IconLibrary = 'fa' | 'mdi' | 'ion' | 'material-icons' | 'material-symbols'; // 'fa' = Font Awesome, 'mdi' = Material Design Icons, 'ion' = Ionicons Web Components, 'material-icons' = Google Material Icons, 'material-symbols' = Google Material Symbols\n\n/**\n * Shared props for the Icon component, independent of whether a class-based `name` or a\n * custom `children` node supplies the glyph.\n */\ninterface IconBaseProps\n extends React.HTMLAttributes<HTMLSpanElement>, BulmaClassesProps {\n /** Additional CSS classes to apply. */\n className?: string;\n /** Text color helper. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /**\n * Text color alias: renders `has-text-<color>`, exactly like `textColor`.\n * Not a filled variant (no `.icon.is-<color>` CSS exists). Prefer\n * `textColor`, which takes precedence when both are set; use `bgColor` for\n * a colored surface.\n */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Background color helper. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /**\n * Legacy icon class string (e.g. `'fas fa-star'`). Only its last segment is read, as the\n * glyph name; the library still comes from `library` or `ConfigProvider`, so\n * `'mdi mdi-rocket'` renders an `fa` class unless the effective library is already `mdi` —\n * set it here or on the provider.\n *\n * @deprecated Use `name` instead.\n */\n icon?: string;\n /**\n * The icon library to use ('fa' = Font Awesome, 'mdi' = Material Design Icons, 'ion' = Ionicons Web Components, 'material-icons' = Google Material Icons, 'material-symbols' = Google Material Symbols). Defaults to the value set in ConfigProvider or 'fa' if not configured. Ignored when `children` supplies the glyph instead of `name`.\n * @defaultValue 'fa'\n */\n library?: IconLibrary; // defaults to ConfigProvider iconLibrary or 'fa'\n /** Icon style variant (e.g. `'solid'`, `'outlined'`, `'rounded'`). Ignored when `children` supplies the glyph instead of `name`. */\n variant?: string; // e.g., 'solid', 'outlined', 'rounded', 'sharp'\n /** Additional modifiers (e.g. `'fa-lg'`, `'fa-spin'`, `'is-size-1'`). Ignored when `children` supplies the glyph instead of `name`. */\n features?: string | string[]; // e.g., 'fa-lg', 'fa-spin', 'is-size-1'\n /**\n * Additional modifiers in the older combined form, parsed into `variant` and `features`.\n *\n * @deprecated Use `variant` and `features` instead.\n */\n libraryFeatures?: string | string[];\n /** Size modifier for the icon container. */\n size?: 'small' | 'medium' | 'large';\n /**\n * Accessible name for an icon that means something on its own. Set it and the container\n * span gets `role=\"img\"` with this `aria-label`, so the name is exactly this text: a\n * Material ligature such as `rocket_launch` inside stays out of it. Leave it unset (or\n * empty) and the icon is decorative: the span renders `aria-hidden=\"true\"` and no name,\n * so it adds nothing to the accessible name of a `Button` or text around it. For an\n * icon-only control, put the name on the control (e.g. `Button`'s `aria-label`) and leave\n * this unset. A non-empty native `aria-label` or `aria-labelledby` passed instead also\n * counts as a name, and an explicit `role` or `aria-hidden` wins over both defaults. An\n * unnamed icon given a `role` or a `tabIndex` of its own isn't hidden, since hiding\n * something focusable is a failure of its own.\n */\n ariaLabel?: string;\n /** Inline style object. */\n style?: React.CSSProperties;\n /** Override the default `'icon'` container class (e.g., `'panel-icon'`). */\n containerClassName?: string; // Override the default 'icon' container class (e.g., 'panel-icon')\n}\n\n/**\n * Props for `Icon` rendering a class-based glyph from an icon library.\n */\nexport interface IconNameProps extends IconBaseProps {\n /** The icon name, with or without its library prefix (e.g. `'star'` or `'fa-star'`). Mutually exclusive with `children`. */\n name: string; // e.g., 'star', 'account', 'home-outline'\n /** A custom node (an inline SVG, a `react-icons` component, …) rendered inside the icon container in place of a class-based glyph. Mutually exclusive with `name`. */\n children?: never;\n}\n\n/**\n * Props for `Icon` rendering a custom node (an inline SVG, a `react-icons` component, a Font\n * Awesome React `<FontAwesomeIcon>`, …) in place of a class-based glyph.\n */\nexport interface IconChildrenProps extends IconBaseProps {\n /** The icon name, with or without its library prefix (e.g. `'star'` or `'fa-star'`). Mutually exclusive with `children`. */\n name?: undefined;\n /** A custom node (an inline SVG, a `react-icons` component, …) rendered inside the icon container in place of a class-based glyph. Mutually exclusive with `name`. */\n // `undefined` is excluded deliberately: the renderer discriminates on `children !== undefined`,\n // so `children={undefined}` would satisfy the type but fall through to the `name` path with no\n // name and render an `fa-undefined` glyph. Excluding it keeps the advertised\n // exactly-one-of-`name`-or-`children` constraint matching what actually renders.\n children: Exclude<React.ReactNode, undefined>;\n}\n\n/**\n * Props for `Icon` naming its glyph through the deprecated `icon` prop instead of `name`.\n *\n * The runtime has always accepted `icon` on its own — it strips a leading library prefix off\n * the class string and falls through to the `name` path — but the type offered no member without\n * a `name` or `children`, so every caller still on the deprecated prop got an error the\n * package could not see — until #663 nothing here type-checked a test or a story, so the\n * three `Icon.test.tsx` cases exercising this path proved the runtime and said nothing about\n * the type. Declaring the path is the honest resolution: it is deprecated, not removed, and a\n * deprecation that does not type-check is a removal announced only to whoever tries it.\n *\n * @deprecated Pass `name` instead. This member goes when `icon` does.\n */\nexport interface IconDeprecatedProps extends IconBaseProps {\n /**\n * Legacy icon class string (e.g. `'fas fa-star'`). Only its last segment is read, as the\n * glyph name; the library still comes from `library` or `ConfigProvider`, so\n * `'mdi mdi-rocket'` renders an `fa` class unless the effective library is already `mdi` —\n * set it here or on the provider.\n *\n * @deprecated Use `name` instead.\n */\n // Required here, optional on `IconBaseProps`: the other two members allow it\n // alongside `name`, and this one is the member where it IS the glyph. Same\n // prose in both places on purpose — the API-docs extractor reads whichever it\n // reaches first, and the two must not drift apart.\n icon: string;\n /** The icon name. Absent on this path — `icon` supplies the glyph. */\n name?: undefined;\n /** A custom node. Mutually exclusive with `icon`. */\n children?: never;\n}\n\n/**\n * Props for the Icon component — a discriminated union of a class-based `name`, a custom\n * `children` node, and the deprecated `icon` class string.\n */\nexport type IconProps = IconNameProps | IconChildrenProps | IconDeprecatedProps;\n\n/**\n * Strips a redundant leading library prefix from an icon name (e.g. `fa-check` -> `check`\n * for the `fa` library, `mdi-account` -> `account` for `mdi`), so `name` behaves the same\n * whether or not the caller includes the prefix. Font Awesome and Material Design Icons docs\n * conventionally refer to icons with their class prefix (`fa-check`), which otherwise gets\n * doubled by `getIconClasses` (producing `fa-fa-check`, matching no glyph).\n *\n * @param {string} name - The icon name, possibly including a redundant library prefix.\n * @param {IconLibrary} library - The icon library the name will be rendered with.\n * @returns {string} The icon name with any redundant leading library prefix removed.\n */\nfunction stripRedundantLibraryPrefix(\n name: string,\n library: IconLibrary\n): string {\n if (!name) {\n return name;\n }\n if (library === 'fa' && name.startsWith('fa-')) {\n return name.substring(3);\n }\n if (library === 'mdi' && name.startsWith('mdi-')) {\n return name.substring(4);\n }\n return name;\n}\n\n/**\n * Gets the correct classes for the icon element based on the library and features.\n *\n * @param {IconLibrary} library - The icon library.\n * @param {string} name - The icon name.\n * @param {string} [variant] - Icon style variant (e.g., 'solid', 'outlined', 'rounded').\n * @param {string | string[]} [features] - Additional library-specific modifiers.\n * @returns {string} The combined class string for the icon.\n */\nfunction getIconClasses(\n library: IconLibrary,\n name: string,\n variant?: string,\n features?: string | string[]\n): string {\n let baseClass: string;\n let iconClass: string;\n const featureList = Array.isArray(features)\n ? features\n : features\n ? [features]\n : [];\n\n switch (library) {\n case 'fa': {\n // Font Awesome: use variant as style ('solid' -> 'fas', 'regular' -> 'far', etc.)\n const styleMap: Record<string, string> = {\n solid: 'fas',\n regular: 'far',\n brands: 'fab',\n light: 'fal',\n duotone: 'fad',\n thin: 'fat',\n };\n const faStyle = variant ? styleMap[variant] || variant : 'fas';\n baseClass = faStyle;\n iconClass = `fa-${name}`;\n return [baseClass, iconClass, ...featureList].join(' ');\n }\n case 'mdi':\n // Material Design Icons: no variants, just features\n baseClass = 'mdi';\n iconClass = `mdi-${name}`;\n return [baseClass, iconClass, ...featureList].join(' ');\n case 'material-icons': {\n // Google Material Icons: map variants to full class names\n const styleVariants: Record<string, string> = {\n filled: 'material-icons',\n outlined: 'material-icons-outlined',\n round: 'material-icons-round',\n sharp: 'material-icons-sharp',\n };\n baseClass = variant\n ? styleVariants[variant] || `material-icons-${variant}`\n : 'material-icons';\n return [baseClass, ...featureList].join(' ');\n }\n case 'material-symbols': {\n // Google Material Symbols: map variants to full class names\n const styleVariants: Record<string, string> = {\n outlined: 'material-symbols-outlined',\n rounded: 'material-symbols-rounded',\n sharp: 'material-symbols-sharp',\n };\n baseClass = variant\n ? styleVariants[variant] || `material-symbols-${variant}`\n : 'material-symbols-outlined';\n return [baseClass, ...featureList].join(' ');\n }\n default:\n // fallback: just icon name and features\n return [name, ...featureList].join(' ');\n }\n}\n\n/**\n * The `Icon` component is a Bulma-styled wrapper for displaying icons from various libraries (Font Awesome, Material Design Icons, Ionicons, Google Material Icons, Material Symbols, etc.).\n *\n * @function\n * @param {IconProps} props - Props for the Icon component.\n * @returns {JSX.Element} The rendered icon element.\n * @see {@link https://bulma.io/documentation/elements/icon/ | Bulma Icon documentation}\n */\nexport const Icon: React.FC<IconProps> = ({\n className,\n textColor,\n bgColor,\n name,\n library,\n variant,\n features,\n libraryFeatures, // Deprecated but maintained for backward compatibility\n size,\n ariaLabel,\n style,\n icon, // Capture and exclude the deprecated 'icon' prop from DOM\n color,\n containerClassName,\n children,\n ...restProps\n}) => {\n // Get the default icon library from context, fallback to 'fa' if not set\n const defaultLibrary = useIconLibrary();\n\n /**\n * Generates Bulma helper classes and separates out remaining props.\n * Note: variant, features, and libraryFeatures are excluded from props spread\n */\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor ?? color,\n backgroundColor: bgColor,\n ...restProps,\n });\n\n // Hoisted unconditionally to respect rules-of-hooks; the branches below\n // pick which result to consume.\n const defaultIconClasses = usePrefixedClassNames('icon', {\n [`is-${size}`]: size,\n });\n const sizeModifierClass = usePrefixedClassNames(\n size ? `is-${size}` : undefined\n );\n\n const bulmaClasses = containerClassName\n ? containerClassName\n : defaultIconClasses;\n\n const iconContainerClasses = classNames(\n bulmaClasses,\n containerClassName && size ? sizeModifierClass : undefined,\n bulmaHelperClasses,\n className\n );\n\n // A named icon is an image, whose name is its label alone, so a ligature inside\n // never leaks into it. An unnamed one is decorative and hidden outright. Spread\n // before `rest`, so a caller's own `role` or `aria-hidden` still wins.\n const named =\n !!ariaLabel || !!restProps['aria-label'] || !!restProps['aria-labelledby'];\n // A caller's own `role` or `tabIndex` on an unnamed icon means it isn't decoration (an\n // icon made a button, say), so it isn't hidden either: `aria-hidden` on something\n // focusable is a failure of its own.\n const a11yProps = named\n ? { role: 'img', 'aria-label': ariaLabel || undefined }\n : restProps.role !== undefined || restProps.tabIndex !== undefined\n ? {}\n : { 'aria-hidden': true };\n\n if (children !== undefined) {\n // `IconChildrenProps`: render the caller's node (an inline SVG, a `react-icons`\n // component, …) in place of a class-based glyph. Library/variant/features don't apply.\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n {children}\n </span>\n );\n }\n\n // `name` is guaranteed once `children` is absent UNLESS the caller is on the deprecated\n // `icon` path, which `IconDeprecatedProps` declares with `name?: undefined`.\n // (`IconChildrenProps['children']` excludes `undefined`, so `children={undefined}` can't\n // slip past into this branch.) The cast covers that third member, and the `!name && icon`\n // fallback below is what fills it in.\n let finalName = name as string;\n if (!name && icon) {\n // If icon prop is provided instead of name, try to parse it\n // e.g., \"mdi mdi-rocket-launch\" -> \"rocket-launch\"\n if (typeof icon === 'string') {\n const parts = icon.split(' ');\n const lastPart = parts[parts.length - 1];\n if (lastPart.startsWith('mdi-')) {\n finalName = lastPart.substring(4); // Remove \"mdi-\" prefix\n } else if (lastPart.startsWith('fa-')) {\n finalName = lastPart.substring(3); // Remove \"fa-\" prefix\n } else {\n finalName = lastPart;\n }\n }\n }\n\n const finalLibrary = library || defaultLibrary || 'fa';\n\n // Normalize a redundant leading library prefix (e.g. \"fa-check\" -> \"check\" when the\n // library is 'fa'), so `name` behaves identically with or without the prefix.\n finalName = stripRedundantLibraryPrefix(finalName, finalLibrary);\n\n if (!finalName) {\n // No glyph to name. Reachable through the public type only as `icon=\"\"`, and otherwise\n // by a plain-JS caller (or one that casts). Building a class off an absent name produced\n // a bogus `fa-undefined` glyph; render the bare container instead, matching the\n // `children` branch.\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n />\n );\n }\n\n // Backward compatibility: if libraryFeatures is provided, parse it for variant and features\n let finalVariant = variant;\n let finalFeatures = features;\n\n if (libraryFeatures && !variant && !features) {\n const legacyFeatures = Array.isArray(libraryFeatures)\n ? libraryFeatures\n : [libraryFeatures];\n\n // For Font Awesome, extract style from features\n if (finalLibrary === 'fa') {\n const faStyle = legacyFeatures.find(f =>\n [\n 'fas',\n 'far',\n 'fab',\n 'fal',\n 'fad',\n 'fat',\n 'solid',\n 'regular',\n 'brands',\n 'light',\n 'duotone',\n 'thin',\n ].includes(f)\n );\n if (faStyle) {\n finalVariant = faStyle;\n finalFeatures = legacyFeatures.filter(f => f !== faStyle);\n } else {\n finalFeatures = legacyFeatures;\n }\n }\n // For Material Icons/Symbols, extract style variant\n else if (\n finalLibrary === 'material-icons' ||\n finalLibrary === 'material-symbols'\n ) {\n const styleVariants =\n finalLibrary === 'material-icons'\n ? ['filled', 'outlined', 'round', 'sharp']\n : ['outlined', 'rounded', 'sharp'];\n\n const styleVariant = legacyFeatures.find(f => styleVariants.includes(f));\n if (styleVariant) {\n finalVariant = styleVariant;\n finalFeatures = legacyFeatures.filter(f => f !== styleVariant);\n } else {\n finalFeatures = legacyFeatures;\n }\n }\n // For others, all features go to finalFeatures\n else {\n finalFeatures = legacyFeatures;\n }\n }\n\n // Handle web components vs CSS-based icons\n if (finalLibrary === 'ion') {\n // For Ionicons, handle variant in the name\n let ionName = finalName;\n if (finalVariant === 'outline') {\n ionName = `${finalName}-outline`;\n } else if (finalVariant === 'sharp') {\n ionName = `${finalName}-sharp`;\n }\n\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n <ion-icon name={ionName} />\n </span>\n );\n }\n\n // Legacy CSS-based icons\n const iClasses = getIconClasses(\n finalLibrary,\n finalName,\n finalVariant,\n finalFeatures\n );\n\n // Material Icons and Material Symbols use text content, not CSS classes for the icon name\n if (\n finalLibrary === 'material-icons' ||\n finalLibrary === 'material-symbols'\n ) {\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n <i className={iClasses}>{finalName}</i>\n </span>\n );\n }\n\n return (\n <span\n className={iconContainerClasses}\n {...a11yProps}\n style={style}\n {...rest}\n >\n <i className={iClasses} />\n </span>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;AAoKA;;;;;;;;;;AAUG;AACH,SAAS,2BAA2B,CAClC,IAAY,EACZ,OAAoB,EAAA;IAEpB,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI;IACb;IACA,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;AAC9C,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1B;IACA,IAAI,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;AAChD,QAAA,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1B;AACA,IAAA,OAAO,IAAI;AACb;AAEA;;;;;;;;AAQG;AACH,SAAS,cAAc,CACrB,OAAoB,EACpB,IAAY,EACZ,OAAgB,EAChB,QAA4B,EAAA;AAE5B,IAAA,IAAI,SAAiB;AACrB,IAAA,IAAI,SAAiB;AACrB,IAAA,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ;AACxC,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EAAA,GACR,IAAI,YAERA,GAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAE,QAAQ,EAAA,CAAI,EAAA,CACrB;AAEX;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -3199,8 +3199,7 @@ function getIconClasses(library, name, variant, features) {
|
|
|
3199
3199
|
*/
|
|
3200
3200
|
const Icon = ({ className, textColor, bgColor, name, library, variant, features, libraryFeatures, // Deprecated but maintained for backward compatibility
|
|
3201
3201
|
size, ariaLabel, style, icon, // Capture and exclude the deprecated 'icon' prop from DOM
|
|
3202
|
-
color
|
|
3203
|
-
containerClassName, children, ...restProps }) => {
|
|
3202
|
+
color, containerClassName, children, ...restProps }) => {
|
|
3204
3203
|
// Get the default icon library from context, fallback to 'fa' if not set
|
|
3205
3204
|
const defaultLibrary = useIconLibrary();
|
|
3206
3205
|
/**
|
|
@@ -3208,7 +3207,7 @@ containerClassName, children, ...restProps }) => {
|
|
|
3208
3207
|
* Note: variant, features, and libraryFeatures are excluded from props spread
|
|
3209
3208
|
*/
|
|
3210
3209
|
const { bulmaHelperClasses, rest } = useBulmaClasses({
|
|
3211
|
-
color: textColor,
|
|
3210
|
+
color: textColor ?? color,
|
|
3212
3211
|
backgroundColor: bgColor,
|
|
3213
3212
|
...restProps,
|
|
3214
3213
|
});
|