feat(types): add carbon__icon-helpers (#43314)

This commit is contained in:
Eric Liu 2020-03-23 08:44:55 -07:00 committed by GitHub
parent b21148cd10
commit db21a0f0c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import { defaultAttributes, getAttributes, formatAttributes, toString, toSvg } from '@carbon/icon-helpers';
defaultAttributes.focusable; // $Expect 'false'
defaultAttributes.preserveAspectRatio; // $Expect 'xMidYMid meet'
getAttributes({ width: 16, height: 16 }); // $ExpectType IconAttributes
formatAttributes({ width: 16, height: 16 }); // $ExpectType string
toString(); // $Expect string
toString({
elem: 'svg',
attrs: { width: 16, height: 16 },
content: [
{ elem: 'path', attrs: { d: '' } },
{ elem: 'circle', attrs: { cx: '', cy: '', r: '' } },
{ elem: 'rect', attrs: { width: '', height: '', x: '', y: '', rx: '' } },
],
}); // $Expect string
toSvg(); // $ExpectType SVGSVGElement
toSvg({
elem: 'svg',
attrs: { width: 16, height: 16 },
content: [
{ elem: 'path', attrs: { d: '' } },
{ elem: 'circle', attrs: { cx: '', cy: '', r: '' } },
{ elem: 'rect', attrs: { width: '', height: '', x: '', y: '', rx: '' } },
],
}); // $Expect SVGSVGElement

56
types/carbon__icon-helpers/index.d.ts vendored Normal file
View File

@ -0,0 +1,56 @@
// Type definitions for @carbon/icon-helpers 10.6
// Project: https://github.com/carbon-design-system/carbon/blob/master/packages/icon-helpers
// Definitions by: Eric Liu <https://github.com/metonym>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.8
export interface Path {
elem: 'path';
attrs: { d: string };
}
export interface Circle {
elem: 'circle';
attrs: { cx: string; cy: string; r: string };
}
export interface Rect {
elem: 'rect';
attrs: { width: string; height: string; x: string; y: string; rx: string };
}
export type IconSize = 16 | 20 | 24 | 32;
export type IconContent = Array<Path | Circle | Rect>;
export interface IconAttributes extends Record<string, any> {
'aria-hidden'?: boolean;
'aria-label'?: string;
'aria-labelledby'?: string;
class?: string;
focusable?: 'true' | 'false';
height: IconSize;
id?: string;
preserveAspectRatio?: string | 'xMidYMid meet';
role?: 'img';
style?: string;
tabindex?: string;
title?: string;
viewBox?: string;
width: IconSize;
}
export interface Descriptor {
elem?: string | 'svg';
attrs?: IconAttributes | {};
content?: IconContent | [];
}
export const defaultAttributes: {
focusable: 'false';
preserveAspectRatio: 'xMidYMid meet';
};
export function getAttributes(attributes: IconAttributes): IconAttributes;
export function formatAttributes(attributes: IconAttributes): string;
export function toString(descriptor?: Descriptor): string;
export function toSvg(descriptor?: Descriptor): SVGSVGElement;

View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6", "DOM"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@carbon/icon-helpers": ["carbon__icon-helpers"]
}
},
"files": ["index.d.ts", "carbon__icon-helpers-tests.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }