UNPKG

1.58 kBPlain TextView Raw
1/*
2 * Copyright 2021 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { BLUEPRINT_ICONS_16_CODEPOINTS } from "./generated/16px/blueprint-icons-16";
18import type { IconName } from "./iconNames";
19// icon sets are identical aside from SVG paths, so we just import the info for the 16px set
20
21/**
22 * Icon codepoints as base 10 number strings. If you need to render these strings
23 * into an SVG document or as `::before` pseudo content, consider using `getIconContentString()`
24 * instead.
25 */
26export const IconCodepoints = BLUEPRINT_ICONS_16_CODEPOINTS;
27
28/**
29 * Returns the hex code content string which represents the codepoint in the icon font
30 * for a given icon. You can render this string to the DOM and if the icon font is loaded
31 * as an active font family, this string will be replaced with the associated icon.
32 */
33export function getIconContentString(icon: IconName) {
34 // parse base 10 number from string, then convert to hex code
35 return String.fromCodePoint(parseInt(IconCodepoints[icon], 10));
36}