diff --git a/package.json b/package.json index f5e3455..a5abde7 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,11 @@ "version": "1.3.0", "description": "Preact + Photon = <3", "main": "preact-photon.js", + "types": "src/index.d.ts", + "files": [ + "src/*.d.ts", + "preact-photon.js" + ], "scripts": { "build": "babel -f $npm_package_main -s -o $npm_package_main < src/index.js", "test": "eslint src test && mocha --compilers js:babel/register test/**/*.js", diff --git a/src/entypo-icons.d.ts b/src/entypo-icons.d.ts new file mode 100644 index 0000000..27d41e4 --- /dev/null +++ b/src/entypo-icons.d.ts @@ -0,0 +1,287 @@ +declare module "preact-photon" { + export type IconIdentifier = + | "note" + | "note-beamed" + | "music" + | "search" + | "flashlight" + | "mail" + | "heart" + | "heart-empty" + | "star" + | "star-empty" + | "user" + | "users" + | "user-add" + | "video" + | "picture" + | "camera" + | "layout" + | "menu" + | "check" + | "cancel" + | "cancel-circled" + | "cancel-squared" + | "plus" + | "plus-circled" + | "plus-squared" + | "minus" + | "minus-circled" + | "minus-squared" + | "help" + | "help-circled" + | "info" + | "info-circled" + | "back" + | "home" + | "link" + | "attach" + | "lock" + | "lock-open" + | "eye" + | "tag" + | "bookmark" + | "bookmarks" + | "flag" + | "thumbs-up" + | "thumbs-down" + | "download" + | "upload" + | "upload-cloud" + | "reply" + | "reply-all" + | "forward" + | "quote" + | "code" + | "export" + | "pencil" + | "feather" + | "print" + | "retweet" + | "keyboard" + | "comment" + | "chat" + | "bell" + | "attention" + | "alert" + | "vcard" + | "address" + | "location" + | "map" + | "direction" + | "compass" + | "cup" + | "trash" + | "doc" + | "docs" + | "doc-landscape" + | "doc-text" + | "doc-text-inv" + | "newspaper" + | "book-open" + | "book" + | "folder" + | "archive" + | "box" + | "rss" + | "phone" + | "cog" + | "tools" + | "share" + | "shareable" + | "basket" + | "bag" + | "calendar" + | "login" + | "logout" + | "mic" + | "mute" + | "sound" + | "volume" + | "clock" + | "hourglass" + | "lamp" + | "light-down" + | "light-up" + | "adjust" + | "block" + | "resize-full" + | "resize-small" + | "popup" + | "publish" + | "window" + | "arrow-combo" + | "down-circled" + | "left-circled" + | "right-circled" + | "up-circled" + | "down-open" + | "left-open" + | "right-open" + | "up-open" + | "down-open-mini" + | "left-open-mini" + | "right-open-mini" + | "up-open-mini" + | "down-open-big" + | "left-open-big" + | "right-open-big" + | "up-open-big" + | "down" + | "left" + | "right" + | "up" + | "down-dir" + | "left-dir" + | "right-dir" + | "up-dir" + | "down-bold" + | "left-bold" + | "right-bold" + | "up-bold" + | "down-thin" + | "left-thin" + | "right-thin" + | "up-thin" + | "ccw" + | "cw" + | "arrows-ccw" + | "level-down" + | "level-up" + | "shuffle" + | "loop" + | "switch" + | "play" + | "stop" + | "pause" + | "record" + | "to-end" + | "to-start" + | "fast-forward" + | "fast-backward" + | "progress-0" + | "progress-1" + | "progress-2" + | "progress-3" + | "target" + | "palette" + | "list" + | "list-add" + | "signal" + | "trophy" + | "battery" + | "back-in-time" + | "monitor" + | "mobile" + | "network" + | "cd" + | "inbox" + | "install" + | "globe" + | "cloud" + | "cloud-thunder" + | "flash" + | "moon" + | "flight" + | "paper-plane" + | "leaf" + | "lifebuoy" + | "mouse" + | "briefcase" + | "suitcase" + | "dot" + | "dot-2" + | "dot-3" + | "brush" + | "magnet" + | "infinity" + | "erase" + | "chart-pie" + | "chart-line" + | "chart-bar" + | "chart-area" + | "tape" + | "graduation-cap" + | "language" + | "ticket" + | "water" + | "droplet" + | "air" + | "credit-card" + | "floppy" + | "clipboard" + | "megaphone" + | "database" + | "drive" + | "bucket" + | "thermometer" + | "key" + | "flow-cascade" + | "flow-branch" + | "flow-tree" + | "flow-line" + | "flow-parallel" + | "rocket" + | "gauge" + | "traffic-cone" + | "cc" + | "cc-by" + | "cc-nc" + | "cc-nc-eu" + | "cc-nc-jp" + | "cc-sa" + | "cc-nd" + | "cc-pd" + | "cc-zero" + | "cc-share" + | "cc-remix" + | "github" + | "github-circled" + | "flickr" + | "flickr-circled" + | "vimeo" + | "vimeo-circled" + | "twitter" + | "twitter-circled" + | "facebook" + | "facebook-circled" + | "facebook-squared" + | "gplus" + | "gplus-circled" + | "pinterest" + | "pinterest-circled" + | "tumblr" + | "tumblr-circled" + | "linkedin" + | "linkedin-circled" + | "dribbble" + | "dribbble-circled" + | "stumbleupon" + | "stumbleupon-circled" + | "lastfm" + | "lastfm-circled" + | "rdio" + | "rdio-circled" + | "spotify" + | "spotify-circled" + | "qq" + | "instagram" + | "dropbox" + | "evernote" + | "flattr" + | "skype" + | "skype-circled" + | "renren" + | "sina-weibo" + | "paypal" + | "picasa" + | "soundcloud" + | "mixi" + | "behance" + | "google-circles" + | "vkontakte" + | "smashing" + | "sweden" + | "db-shape" + | "logo-db" +} diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..2527b3a --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,233 @@ +import { h, Component, AnyComponent, Attributes } from "preact" + +declare module "preact-photon" { + type E = JSX.IntrinsicElements + type RenderFunction = (props: P & Attributes, state: S) => JSX.Element + + interface IStylable { + class?: string + } + + /** App "footer" bar, shown at the bottom of a window. + * @class + */ + export class Footer extends Component { + public render: RenderFunction + } + + /** App "header" bar, shown at the top of a window. + * @class + */ + export class Header extends Component { + public render: RenderFunction + } + + /** Toolbar title. + * @class + */ + export class Title extends Component { + public render: RenderFunction + } + + /** Group buttons together. + * @class + * @example + * + * + * + * + */ + export class ButtonGroup extends Component { + public render: RenderFunction + } + + /** Buttons. They are clickable. + * @class + * @param props.icon If supplied, shows the given named icon to the left of the button text + * @param props.primary Make the button display as a default action + * @example + * + * @example + * + * @example + * + * @example + * + * @example + * + * @example + * + * @example + * + * @example + * + */ + export class Button extends Component< + { + icon?: string + primary?: boolean + large?: boolean + mini?: boolean + dropdown?: boolean + form?: boolean + type?: "positive" | "negative" | "warning" + } & E["button"] + > { + public render: RenderFunction + } + + /** A named icon/glyph from the nice built-in list of icons. + * @class + * @example + * + */ + export class Icon extends Component< + { text?: string; name: IconIdentifier } & E["span"] + > { + public render: RenderFunction + } + + /** Groups tabs together into a horizontal. + * @class + * @example + * + * One + * Two + * + */ + export class TabGroup extends Component { + public static Item: typeof Tab + public render: RenderFunction + } + + /** For building MDIs. Has a close button by default, add `close="false"` to turn it off. + * @class + * @example + * title + * @example + * title + */ + export class Tab extends Component<{ close?: false | "false" } & E["div"]> { + public render: RenderFunction + } + + /** Group of sidebar navigation items + * @class + * @example + * + * Faves + * Foo + * + */ + export class NavGroup extends Component { + public static Title: typeof NavGroupTitle + public static Item: typeof NavGroupItem + public render: RenderFunction + } + + /** Title for a group of navigation items. + * @class + * @example + * Faves + */ + export class NavGroupTitle extends Component { + public render: RenderFunction + } + + /** A single navigation item with optional icon. + * @class + * @example + * Home + * @example + * Documents + */ + export class NavGroupItem extends Component< + { icon: IconIdentifier } & E["span"] + > { + public render: RenderFunction + } + + /** Group of list items + * @class + * @example + * + * + * + * + * Foo + * + */ + export class ListGroup extends Component { + public static Header: typeof ListGroupHeader + public static Item: typeof ListGroupItem + public render: RenderFunction + } + + /** Top header item in a list group. + * @class + * @example + * + * + * + */ + export class ListGroupHeader extends Component { + public render: RenderFunction + } + + /** A single navigation item with optional icon. + * @class + * @example + * Home + */ + export class ListGroupItem extends Component { + public render: RenderFunction + } + + /** HTML `
` */ + export class Form extends Component { + public static Group: typeof FormGroup + public static CheckBox: typeof FormCheckBox + public static Radio: typeof FormRadio + public static Actions: typeof FormActions + public render: RenderFunction + } + + /** Basically `
` */ + export class FormGroup extends Component { + public render: RenderFunction + } + + /** Basically `` */ + export class FormCheckBox extends Component< + { + name: string + checked?: boolean + value?: string | number | string[] + label?: AnyComponent + } & E["div"] + > { + public render: RenderFunction + } + + /** Basically `` */ + export class FormRadio extends Component< + { + name: string + checked?: boolean + value?: string | number | string[] + label?: AnyComponent + } & E["div"] + > { + public render: RenderFunction + } + + /** Group buttons at the bottom of a form. */ + export class FormActions extends Component { + public render: RenderFunction + } + + /** Just an enhanced `` */ + export class Table extends Component<{ striped?: boolean } & E["table"]> { + public render: RenderFunction + } +} diff --git a/src/index.js b/src/index.js index 530e212..ac48e1a 100644 --- a/src/index.js +++ b/src/index.js @@ -14,54 +14,14 @@ let componentNode = (Name, classes) => component( ({ children, ...props }) => ( {children} )); -/** App "footer" bar, shown at the bottom of a window. - * @class - */ export const Header = componentNode('header', ['toolbar toolbar-header']); -/** App "header" bar, shown at the top of a window. - * @class - */ export const Footer = componentNode('footer', ['toolbar toolbar-footer']); -/** Toolbar title. - * @class - */ export const Title = componentNode('h1', 'title'); - -/** Group buttons together. - * @class - * @example - * - * - * - * - */ export const ButtonGroup = componentNode('div', 'btn-group'); -/** Buttons. They are clickable. - * @class - * @param {object} props - * @param {string} [icon] If supplied, shows the given named icon to the left of the button text - * @param {boolean} [primary=false] Make the button display as a default action - * @example - * - * @example - * - * @example - * - * @example - * - * @example - * - * @example - * - * @example - * - * @example - * - */ export const Button = component( ({ class: className, children, @@ -87,34 +47,12 @@ export const Button = component( ({ )); - -/** A named icon/glyph from the nice built-in list of icons. - * @class - * @example - * - */ export const Icon = component( ({ class:className, text, name, children, ...props }) => ( { children } )); - -/** Groups tabs together into a horizontal. - * @class - * @example - * - * One - * Two - * - */ export const TabGroup = componentNode('div', 'tab-group'); -/** For building MDIs. Has a close button by default, add `close="false"` to turn it off. - * @class - * @example - * title - * @example - * title - */ export const Tab = component( ({ class:className, close, children, ...props }) => (
{ String(close)==='false' ? null : } @@ -124,31 +62,10 @@ export const Tab = component( ({ class:className, close, children, ...props }) = TabGroup.Item = Tab; - -/** Group of sidebar navigation items - * @class - * @example - * - * Faves - * Foo - * - */ export const NavGroup = componentNode('nav', 'nav-group'); -/** Title for a group of navigation items. - * @class - * @example - * Faves - */ NavGroup.Title = componentNode('h5', 'nav-group-title'); -/** A single navigation item with optional icon. - * @class - * @example - * Home - * @example - * Documents - */ NavGroup.Item = component( ({ class:className, icon, children, ...props }) => ( { icon ? () : null } @@ -156,43 +73,16 @@ NavGroup.Item = component( ({ class:className, icon, children, ...props }) => ( )); - -/** Group of list items - * @class - * @example - * - * - * - * - * Foo - * - */ export const ListGroup = componentNode('ul', 'list-group'); -/** Top header item in a list group. - * @class - * @example - * - * - * - */ ListGroup.Header = componentNode('li', 'list-group-header'); -/** A single navigation item with optional icon. - * @class - * @example - * Home - */ ListGroup.Item = componentNode('li', 'list-group-item'); - -/** HTML `` */ const Form = componentNode('form'); -/** Basically `
` */ Form.Group = componentNode('div', 'form-group'); -/** Basically `` */ Form.CheckBox = component( ({ class:className, name, checked, value, label, children, ...props }) => (
)); -/** Basically `` */ Form.Radio = component( ({ class:className, name, checked, value, label, children, ...props }) => (
)); -/** Group buttons at the bottom of a form. */ Form.Actions = componentNode('div', 'form-actions'); - -/** Just an enhanced `
` */ export const Table = component( ({ class:className, striped, children, ...props }) => (
{ children }
)); - - -// export class Header extends Component { -// render({ toolbar, title, children }) { -// return ( -//
-// { title ? (

{ title }

) : null } -// { children } -//
-// ); -// } -// } -// -// export class Button extends Component { -// render({ icon, children }) { -// return ( -// -// ); -// } -// }