@drivy/cobalt
Version:
Opinionated design system for Drivy's projects.
30 lines (27 loc) • 1.32 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import cx from 'classnames';
import * as index from '../../icons/countries/index.js';
import { countries } from '../../tokens/index.js';
import 'lodash.throttle';
import eqSet from '../utils/eqSet.js';
if (!eqSet(new Set(Object.keys(index)), new Set(Object.keys(countries.flags))))
throw new Error("Flag sources and tokens are not consistent. Did you add the source and export it");
const BUNDLED_FLAGS = Object.freeze(Object.keys(countries.flags).reduce((bundledFlags, name) => {
bundledFlags[name] = index[name];
return bundledFlags;
}, {}));
const Flag = ({ country, size = 24, className }) => {
const _className = cx("cobalt-Flag", className, {
"cobalt-Flag--size16": size === 16,
"cobalt-Flag--size20": size === 20,
"cobalt-Flag--size32": size === 32,
});
const countryFlag = BUNDLED_FLAGS[country];
if (countryFlag == null)
throw new Error(`'${country}' Flag can not be found. Did you add the source and export it`);
return (jsx("span", { className: _className,
// biome-ignore lint/security/noDangerouslySetInnerHtml: Should generated SVGR components like icons
dangerouslySetInnerHTML: { __html: countryFlag } }));
};
export { BUNDLED_FLAGS, Flag };
//# sourceMappingURL=index.js.map