UNPKG

@teaui/preact

Version:

Preact renderer for TeaUI

173 lines (172 loc) 9.14 kB
import type * as preact from 'preact'; import type { Accordion as WrAccordion, Box as WrBox, Button as WrButton, Checkbox as WrCheckbox, Collapsible as WrCollapsible, CollapsibleText as WrCollapsibleText, ConsoleLog as WrConsoleLog, Digits as WrDigits, Drawer as WrDrawer, HotKey as WrHotKey, Keyboard as WrKeyboard, Mouse as WrMouse, Stack as WrStack, Input as WrInput, Progress as WrProgress, Scrollable as WrScrollable, Separator as WrSeparator, Slider as WrSlider, Space as WrSpace, Spinner as WrSpinner, Tabs as WrTabs, ToggleGroup as WrToggleGroup, ViewProps } from '@teaui/core'; import { TextProvider, TextStyle } from './components/TextReact.js'; export { FontStyle } from './components/FontStyle.js'; export type { FontStyleValue } from './components/FontStyle.js'; type Children = 'children' | 'child'; type TUIView<T extends abstract new (arg: any, ...args: any) => any, OmitProps extends keyof ConstructorParameters<T>[0] = Children> = Omit<NonNullable<ConstructorParameters<T>[0]>, OmitProps>; type TUIContainer<T extends abstract new (arg: any, ...args: any) => any, ChildrenProps extends keyof NonNullable<ConstructorParameters<T>[0]> = Children> = TUIView<T, ChildrenProps> & { [Key in ChildrenProps]?: preact.ComponentChildren; }; export type CheckboxProps = TUIView<typeof WrCheckbox>; export type CollapsibleTextProps = TUIView<typeof WrCollapsibleText>; export type ConsoleProps = TUIView<typeof WrConsoleLog>; export type DigitsProps = TUIView<typeof WrDigits>; export type DropdownProps = { choices: [string, any][]; selected?: any; onSelect?: (value: any) => void; multiple?: boolean; title?: string; theme?: string; height?: number | 'shrink'; width?: number | 'shrink'; flex?: number; }; export type HeaderProps = { text?: string; }; export type HotKeyProps = TUIView<typeof WrHotKey>; export type KeyboardProps = TUIContainer<typeof WrKeyboard>; export type MouseProps = TUIContainer<typeof WrMouse>; export type InputProps = TUIView<typeof WrInput>; export type ProgressProps = TUIView<typeof WrProgress>; export type SeparatorProps = TUIView<typeof WrSeparator>; export type SliderProps = TUIView<typeof WrSlider>; export type SpaceProps = TUIView<typeof WrSpace>; export type SpinnerProps = TUIView<typeof WrSpinner>; export type ToggleGroupProps = TUIView<typeof WrToggleGroup>; export type BoxProps = TUIContainer<typeof WrBox>; export type ButtonProps = TUIContainer<typeof WrButton>; export type CollapsibleProps = TUIContainer<typeof WrCollapsible, 'collapsed' | 'expanded' | 'children'>; export type ScrollableProps = TUIContainer<typeof WrScrollable>; export type StackProps = TUIContainer<typeof WrStack>; export type StyleProps = TUIContainer<typeof TextStyle>; export type TextProps = TUIContainer<typeof TextProvider>; export type AccordionProps = TUIContainer<typeof WrAccordion>; export type AccordionSectionProps = TUIContainer<typeof WrAccordion.Section>; export type DrawerProps = TUIContainer<typeof WrDrawer, 'content' | 'drawer' | 'children'>; export type TabsProps = TUIContainer<typeof WrTabs>; export type TabsSectionProps = TUIContainer<typeof WrTabs.Section>; declare module 'preact' { namespace JSX { interface IntrinsicElements { 'tui-br': {}; 'tui-checkbox': CheckboxProps; 'tui-collapsible-text': CollapsibleTextProps; 'tui-console': ConsoleProps; 'tui-digits': DigitsProps; 'tui-dropdown': DropdownProps; 'tui-hotkey': HotKeyProps; 'tui-keyboard': KeyboardProps; 'tui-mouse': MouseProps; 'tui-h1': HeaderProps; 'tui-h2': HeaderProps; 'tui-h3': HeaderProps; 'tui-h4': HeaderProps; 'tui-h5': HeaderProps; 'tui-h6': HeaderProps; 'tui-input': InputProps; 'tui-progress': ProgressProps; 'tui-separator': SeparatorProps; 'tui-slider': SliderProps; 'tui-space': SpaceProps; 'tui-spinner': SpinnerProps; 'tui-toggle-group': ToggleGroupProps; 'tui-tree': ViewProps; 'tui-box': BoxProps; 'tui-button': ButtonProps; 'tui-collapsible': CollapsibleProps; 'tui-scrollable': ScrollableProps; 'tui-stack': StackProps; 'tui-style': StyleProps; 'tui-text': TextProps; 'tui-accordion': AccordionProps; 'tui-accordion-section': AccordionSectionProps; 'tui-drawer': DrawerProps; 'tui-tabs': TabsProps; 'tui-tabs-section': TabsSectionProps; } } } export declare function Br(): preact.JSX.Element; export declare function Checkbox(reactProps: CheckboxProps): preact.JSX.Element; export declare function CollapsibleText(reactProps: CollapsibleTextProps): preact.JSX.Element; export declare function ConsoleLog(reactProps: ConsoleProps): preact.JSX.Element; export declare function Digits(reactProps: DigitsProps): preact.JSX.Element; export declare function Dropdown(reactProps: DropdownProps): preact.JSX.Element; export declare function HotKey(reactProps: HotKeyProps): preact.JSX.Element; export declare function Keyboard({ children, ...props }: KeyboardProps): preact.JSX.Element; export declare function Mouse({ children, ...props }: MouseProps): preact.JSX.Element; export declare function H1(reactProps: HeaderProps): preact.JSX.Element; export declare function H2(reactProps: HeaderProps): preact.JSX.Element; export declare function H3(reactProps: HeaderProps): preact.JSX.Element; export declare function H4(reactProps: HeaderProps): preact.JSX.Element; export declare function H5(reactProps: HeaderProps): preact.JSX.Element; export declare function H6(reactProps: HeaderProps): preact.JSX.Element; export declare function Input(reactProps: InputProps): preact.JSX.Element; export declare function Progress(reactProps: ProgressProps): preact.JSX.Element; interface Separator { (reactProps: SeparatorProps): preact.JSX.Element; horizontal(reactProps: Omit<SeparatorProps, 'direction'>): preact.JSX.Element; vertical(reactProps: Omit<SeparatorProps, 'direction'>): preact.JSX.Element; } export declare const Separator: Separator; interface Slider { (reactProps: SliderProps): preact.JSX.Element; horizontal(reactProps: Omit<SliderProps, 'direction'>): preact.JSX.Element; vertical(reactProps: Omit<SliderProps, 'direction'>): preact.JSX.Element; } export declare const Slider: Slider; export declare function Space(reactProps: SpaceProps): preact.JSX.Element; export declare function Spinner(reactProps: SpinnerProps): preact.JSX.Element; export declare function ToggleGroup(reactProps: ToggleGroupProps): preact.JSX.Element; interface TreeProps<T> extends ViewProps { data: T[]; render: (datum: T) => preact.ComponentChildren; getChildren?: (datum: T) => T[] | undefined; title: preact.ComponentChildren | string; } export declare function Tree<T>(reactProps: TreeProps<T>): preact.JSX.Element; export declare function Box(reactProps: BoxProps): preact.JSX.Element; export declare function Button(reactProps: ButtonProps): preact.JSX.Element; export declare function Collapsible(reactProps: CollapsibleProps): preact.JSX.Element; interface Stack { (reactProps: StackProps): preact.JSX.Element; down(reactProps: Omit<StackProps, 'direction'>): preact.JSX.Element; up(reactProps: Omit<StackProps, 'direction'>): preact.JSX.Element; left(reactProps: Omit<StackProps, 'direction'>): preact.JSX.Element; right(reactProps: Omit<StackProps, 'direction'>): preact.JSX.Element; } export declare const Stack: Stack; export declare function Scrollable(reactProps: ScrollableProps): preact.JSX.Element; /** * <Style /> is similar to <Text/> but only allows inline styles (bold, etc). * Does not support align or wrap (block styles). Does not support 'font', because * font is not encodable via SGR codes (and that's how I'm styling and * concatenating the text nodes). */ export declare function Style(reactProps: StyleProps): preact.JSX.Element; /** * <Text /> is a container that sets the text properties of child TextLiterals * (font, style) and TextContainers (wrap, alignment) */ export declare function Text(reactProps: TextProps): preact.JSX.Element; interface Accordion { (reactProps: AccordionProps): preact.JSX.Element; Section(reactProps: Omit<AccordionSectionProps, 'direction'>): preact.JSX.Element; } export declare const Accordion: Accordion; interface Drawer { (reactProps: DrawerProps): preact.JSX.Element; top(reactProps: Omit<DrawerProps, 'location'>): preact.JSX.Element; right(reactProps: Omit<DrawerProps, 'location'>): preact.JSX.Element; bottom(reactProps: Omit<DrawerProps, 'location'>): preact.JSX.Element; left(reactProps: Omit<DrawerProps, 'location'>): preact.JSX.Element; } export declare const Drawer: Drawer; interface Tabs { (reactProps: TabsProps): preact.JSX.Element; Section(reactProps: Omit<TabsSectionProps, 'direction'>): preact.JSX.Element; } export declare const Tabs: Tabs;