Add type declarations for @hig/button (#39106)

* Add typedefs for @hig/button

* LF -> CRLF

* Add TypeScript version

* Update TS version to 3.0 for 'unknown'

* Turn off automatic exporting
This commit is contained in:
matthewbryant95 2019-10-15 23:18:16 +01:00 committed by Andrew Branch
parent dc7bddcb5d
commit e70fe61d28
4 changed files with 161 additions and 0 deletions

View File

@ -0,0 +1,61 @@
import * as React from 'react';
import Button, { targets, types, widths, AvailableTargets, AvailableTypes, AvailableWidths } from '@hig/button';
/** Button */
const emptyFunc = () => {};
const disabled = true;
const icon = <div />;
const link = '';
const onClick = emptyFunc;
const onBlur = emptyFunc;
const onFocus = emptyFunc;
const onHover = emptyFunc;
const onMouseDown = emptyFunc;
const onMouseEnter = emptyFunc;
const onMouseLeave = emptyFunc;
const onMouseUp = emptyFunc;
const stylesheet = emptyFunc;
const target = targets.BLANK;
const title = '';
const type = types.FLAT;
const width = widths.GROW;
// Minimal props
<Button title="button" />;
// All props
<Button
disabled={disabled}
icon={icon}
link={link}
onClick={onClick}
onBlur={onBlur}
onFocus={onFocus}
onHover={onHover}
onMouseDown={onMouseDown}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onMouseUp={onMouseUp}
stylesheet={stylesheet}
target={target}
title={title}
type={type}
width={width}
/>;
/** Targets */
const target1: AvailableTargets = targets.BLANK;
const target2: AvailableTargets = targets.PARENT;
const target3: AvailableTargets = targets.SELF;
const target4: AvailableTargets = targets.TOP;
/** Types */
const types1: AvailableTypes = types.FLAT;
const types2: AvailableTypes = types.OUTLINE;
const types3: AvailableTypes = types.PRIMARY;
const types4: AvailableTypes = types.SECONDARY;
const types5: AvailableTypes = types.SOLID;
/** Widths */
const widths1: AvailableWidths = widths.GROW;
const widths2: AvailableWidths = widths.SHRINK;

79
types/hig__button/index.d.ts vendored Normal file
View File

@ -0,0 +1,79 @@
// Type definitions for hig__button 1.4
// Project: https://github.com/Autodesk/hig/tree/development/packages/button
// Definitions by: Matthew Bryant <https://github.com/matthewbryant95>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// Turn off automatic exporting
export {};
import * as React from 'react';
type Callback = () => void;
export interface Targets {
SELF: '_self';
BLANK: '_blank';
PARENT: '_parent';
TOP: '_top';
}
export interface Types {
FLAT: 'flat';
OUTLINE: 'outline';
SOLID: 'solid';
/** @deprecated */
PRIMARY: 'primary';
/** @deprecated */
SECONDARY: 'secondary';
}
export interface Widths {
SHRINK: 'shrink';
GROW: 'grow';
}
export type AvailableTargets = Targets[keyof Targets];
export type AvailableTypes = Types[keyof Types];
export type AvailableWidths = Widths[keyof Widths];
export interface Props {
/** Prevents user interaction with the button */
disabled?: boolean;
/** A @hig/icon element */
icon?: JSX.Element;
/** Sets the link of a button */
link?: string;
/** Triggers when you click the button */
onClick?: Callback;
/** Triggers blur when focus is moved away from icon */
onBlur?: Callback;
/** Triggers when focus is moved to button */
onFocus?: Callback;
/** Triggers when you hover over the button */
onHover?: Callback;
/** Triggers when the user's mouse is pressed over the button */
onMouseDown?: Callback;
/** Triggers when the user's mouse is over the button */
onMouseEnter?: Callback;
/** Triggers when the user's mouse is no longer over the button */
onMouseLeave?: Callback;
/** Triggers when the user's mouse is no longer pressed over the button */
onMouseUp?: Callback;
/** Adds custom/overriding styles */
stylesheet?: unknown;
/** Specifies where to display the linked URL */
target?: AvailableTargets;
/** Sets the title of a button */
title: string;
/** Specifies type of button */
type?: AvailableTypes;
/** Specifies width of button */
width?: AvailableWidths;
}
export const availableTargets: AvailableTargets;
export const availableTypes: AvailableTypes;
export const availableWidths: AvailableWidths;
export const targets: Targets;
export const types: Types;
export const widths: Widths;
export default class Button extends React.Component<Props> {}

View File

@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"jsx": "react",
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@hig/button": ["hig__button"]
}
},
"files": ["index.d.ts", "hig__button-tests.tsx"]
}

View File

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