diff --git a/types/react-elemental/index.d.ts b/types/react-elemental/index.d.ts new file mode 100644 index 0000000000..df15c2201d --- /dev/null +++ b/types/react-elemental/index.d.ts @@ -0,0 +1,462 @@ +// Type definitions for React Elemental 1.2 +// Project: https://github.com/LINKIWI/react-elemental +// Definitions by: Fernando Chen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 +import { + AnchorHTMLAttributes, + Component, + CSSProperties, + FunctionComponent, + HTMLAttributes, + ImgHTMLAttributes, + InputHTMLAttributes, + ReactElement, + ReactNode, + TextareaHTMLAttributes +} from 'react'; + +export type AlertType = 'info' | 'success' | 'warn' | 'error'; +export type AlertSize = 'alpha' | 'beta'; +export interface AlertProps { + readonly type?: AlertType; + readonly size?: AlertSize; + readonly title: string; + readonly message: string | ReactElement; + readonly dismissible?: boolean; + readonly style?: CSSProperties; + readonly onDismiss?: () => void; +} + +/** + * Educational status alerts. + */ +export class Alert extends Component { +} + +export type ButtonSize = 'alpha' | 'beta' | 'gamma'; +export interface ButtonProps { + readonly color?: string; + readonly size?: ButtonSize; + readonly text?: string; + readonly disabled?: boolean; + readonly secondary?: boolean; + readonly style?: CSSProperties; + readonly children?: any; +} + +/** + * Button component. + */ +export class Button extends Component { +} + +export interface CheckboxProps { + readonly checked?: boolean; + readonly label?: string; + readonly style?: CSSProperties; + readonly disabled?: boolean; + readonly onChange?: (checked: boolean) => void; + readonly children?: ReactNode; +} +export interface CheckboxState { + readonly isHover: boolean; + readonly isFocus: boolean; +} + +/** + * Styled checkbox element. + */ +export class Checkbox extends Component { +} + +export interface ImageProps extends ImgHTMLAttributes { + readonly alt: string; + readonly color?: string; + readonly width?: string; + readonly height?: string; + readonly lazy?: boolean; + readonly showIntermediate?: boolean; + readonly style?: CSSProperties; + readonly imgStyle?: object; +} +export interface ImageState { + readonly load: string; +} + +/** + * Wrapper for external images. + */ +export class Image extends Component { +} + +export interface LabelProps { + readonly label?: string; + readonly sublabel?: string; +} + +/** + * Text label accompanying an input field. + */ +export const Label: FunctionComponent; + +export type LinkType = 'regular' | 'plain' | 'underline'; +export interface LinkProps extends AnchorHTMLAttributes { + readonly type?: LinkType; + readonly ref?: string; + readonly activeColor?: string; + readonly style?: CSSProperties; + readonly children?: ReactNode; +} + +/** + * Styled link element. + */ +export class Link extends Component { +} + +export interface LoadingBarProps { + readonly color?: string; + readonly thickness?: number; + readonly duration?: number; + readonly delay?: number; + readonly style?: CSSProperties; +} +export interface LoadingBarState { + readonly position: number; +} + +/** + * Indeterminate loading bar component. + */ +export class LoadingBar extends Component { +} + +export type ModalSize = 'alpha' | 'beta' | 'gamma'; +export interface ModalProps { + readonly size?: ModalSize; + readonly persistent?: boolean; + readonly onHide?: () => void; + readonly style?: CSSProperties; + readonly children?: any; +} +export interface ModalState { + readonly modal: HTMLDivElement; + readonly windowWidth: number; + readonly windowHeight: number; +} + +/** + * Container for a full-page modal dialog. + */ +export class Modal extends Component { +} + +export type PulsatorSize = 'alpha' | 'beta' | 'gamma' | 'delta'; +export interface PulsatorProps { + readonly color?: string; + readonly size?: PulsatorSize; + readonly inactive?: boolean; + readonly transparent?: boolean; + readonly style?: CSSProperties; +} +export interface PulsatorState { + readonly color: any; +} + +/** + * Indeterminate progress indication spinner. + */ +export class Pulsator extends Component { +} + +export type RadioGroupProps = HTMLAttributes & { + readonly options?: Array<{ + readonly value: string; + readonly label: string | ReactNode; + readonly disabled?: boolean; + }>; + readonly value?: string; + readonly accentColor?: string; + readonly idleColor?: string; + readonly radioRenderer?: (option: ReactElement, idx: number, options: ReactElement[]) => ReactElement; + readonly onChange?: (value: string) => void; +}; + +/** + * Group of individually selectable radio buttons. + */ +export class RadioGroup extends Component { +} + +export interface SelectListProps { + readonly placeholder?: string; + readonly options?: Array<{ + readonly label: string; + readonly value: string; + }>; + readonly width?: number | string; + readonly height?: number; + readonly error?: string; + readonly style?: CSSProperties; + readonly onChange?: (value: string) => void; +} +export interface SelectListState { + readonly isExpanded: boolean; + readonly isFocused: boolean; + readonly isHovered: boolean; + readonly selectedOption: { + readonly label: any; + readonly value: string; + }; + readonly highlightedIdx: number | null; +} + +/** + * Dropdown menu component. + */ +export class SelectList extends Component { +} + +export interface SpacingProps { + readonly padding?: boolean; + readonly size?: string; + readonly top?: boolean; + readonly right?: boolean; + readonly bottom?: boolean; + readonly left?: boolean; + readonly inline?: boolean; + readonly style?: CSSProperties; + readonly children?: any; +} + +/** + * Spacing component to add padding and margins. + */ +export const Spacing: FunctionComponent; + +export type SpinnerSize = 'alpha' | 'beta' | 'gamma' | 'delta'; +export interface SpinnerProps { + readonly size?: SpinnerSize; + readonly ringColor?: string; + readonly accentColor?: string; + readonly duration?: number; + readonly thickness?: number; + readonly style?: CSSProperties; +} + +/** + * Indeterminate progress indication spinner. + */ +export class Spinner extends Component { +} + +export interface TabsProps { + readonly options?: Array<{ + readonly value: string; + readonly label: string | ReactNode; + }>; + readonly value?: string; + readonly secondary?: boolean; + readonly fit?: boolean; + readonly invert?: boolean; + readonly onChange?: (value: string) => void; + readonly style?: CSSProperties; +} + +/** + * Horizontally organized segments of options. + */ +export class Tabs extends Component { +} + +export type TagSize = 'alpha' | 'beta'; +export interface TagProps { + readonly outlineColor?: string; + readonly backgroundColor?: string; + readonly text: string; + readonly size?: TagSize; + readonly dismissible?: boolean; + readonly onDismiss?: () => void; + readonly style?: CSSProperties; +} + +/** + * Textual status indicators. + */ +export const Tag: FunctionComponent; + +export interface TextProps { + readonly secondary?: boolean; + readonly size?: string; + readonly color?: string; + readonly bold?: boolean; + readonly inline?: boolean; + readonly uppercase?: boolean; + readonly center?: boolean; + readonly right?: boolean; + readonly style?: CSSProperties; + readonly children?: ReactNode; +} + +/** + * Text component with automatic typeface formatting. + */ +export class Text extends Component { +} + +export type TextAreaProps = TextFieldProps & { + readonly error?: string; + readonly secondary?: boolean; + readonly style?: CSSProperties; +}; + +/** + * Styled textarea element for blobs of text input. + * + * This component behaves similarly to TextField, with some minor modifications. + */ +export const TextArea: FunctionComponent; + +export type TextFieldProps = TextareaHTMLAttributes & InputHTMLAttributes & { + readonly error?: string; + readonly secondary?: boolean; + readonly textarea?: boolean; + readonly style?: CSSProperties; +}; + +/** + * Input element for accepting user text input. + */ +export class TextField extends Component { +} + +export interface ToastProps { + readonly color?: string; + readonly accent?: string; + readonly style?: CSSProperties; + readonly children?: ReactNode; +} + +/** + * Fixed-position notification element. This component is purely presentational; in actual usage, + * it should be wrapped in a manager to handle logic for conditional display. + */ +export const Toast: FunctionComponent; + +export interface TooltipProps { + readonly contents: ReactElement; + readonly persistent?: boolean; + readonly width?: number | string; + readonly offset?: number; + readonly top?: boolean; + readonly bottom?: boolean; + readonly style?: CSSProperties; + readonly children: ReactNode; +} + +export interface TooltipState { + readonly displayTooltip: any; +} + +/** + * Wrap an arbitrary element with a tooltip next to the element on hover. + */ +export class Tooltip extends Component { +} + +export interface ElementalProps { + readonly fontOpts?: { + readonly primary?: { + readonly regular?: string; + readonly bold?: string; + }; + readonly secondary?: { + readonly regular?: string; + readonly bold?: string; + }; + }; + readonly colorOpts?: { + readonly primary?: string; + readonly primaryLight?: string; + readonly primaryDark?: string; + }; + readonly children: ReactNode; +} + +/** + * Component that declaratively wraps logic for idempotently bootstrapping the library. Client code + * can be contained within the children of this component at the highest level of the application. + */ +export class Elemental extends Component {} + +export interface FontOpts { + primary?: { + regular?: string; + bold?: string; + }; + secondary?: { + regular?: string; + bold?: string; + }; +} + +export interface ColorOpts { + primary?: string; + primaryLight?: string; + primaryDark?: string; +} + +/** + * Bootstrap Elemental. This will inject all necessary global CSS declarations and initialize custom + * style overrides passed in as options. + * + * @param fontOpts Describes the primary and secondary fonts. + * @param colorOpts Optional color overrides for the library's default primary colors. + */ +export function bootstrap(fontOpts?: FontOpts, colorOpts?: ColorOpts): void; + +export const colors: { + black: string; + white: string; + transparent: string; + greenLight: string; + green: string; + redLight: string; + red: string; + blueLight: string; + blue: string; + blueDark: string; + orangeLight: string; + orange: string; + yellow: string; + yellowLight: string; + purpleLight: string; + purple: string; + purpleDark: string; + primary: string; + primaryLight: string; + primaryDark: string; + [colorName: string]: string; +}; + +export const sizes: { + alpha: string; + beta: string; + gamma: string; + delta: string; + epsilon: string; + iota: string; + kilo: string; + lambda: string; +}; + +export const spacing: { + default: string; + micro: string + tiny: string + small: string + large: string + huge: string + enormous: string; +}; diff --git a/types/react-elemental/react-elemental-tests.tsx b/types/react-elemental/react-elemental-tests.tsx new file mode 100644 index 0000000000..da34a46307 --- /dev/null +++ b/types/react-elemental/react-elemental-tests.tsx @@ -0,0 +1,148 @@ +import * as React from 'react'; +import { + Alert, + Button, + Checkbox, + colors, + Elemental, + Image, + Link, + LoadingBar, + Modal, + Pulsator, + RadioGroup, + SelectList, + Spacing, + Spinner, + Tabs, + Tag, + Text, + TextArea, + TextField, + Toast, + Tooltip +} from 'react-elemental'; + +class App extends React.Component { + handleChange = (key: string) => (value: any) => this.setState({ [key]: value }); + onClick: React.MouseEventHandler = (evt) => evt.preventDefault(); + + render() { + return ( + + + ( + + {option} + + )} + onChange={this.handleChange('radio-group')} + /> + Map of Great Britain + + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + + + + + + Tooltip contents + + } + bottom + > + + Text + + + + + + Use plain links to disable the underline on hover + +