-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(poc): add jsx implementation 4 prompts
- Loading branch information
Showing
15 changed files
with
122 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Text } from '~/lib/prompts/' | ||
|
||
const p = <Text message='Test' /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./text" | ||
export * from "./types" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Component } from "./types" | ||
|
||
export function jsxDEV(component: Component, props: { children: Array<any>, [x: string]: any }): any { | ||
console.log("Parsing JSX props:", props, "\n") | ||
return component(props) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { Component } from "./types" | ||
|
||
export function jsx(component: Component, props: { children: Array<any>, [x: string]: any }): any { | ||
return component(props) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Component = (props: unknown) => any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { State } from "@clack/core" | ||
import isUnicodeSupported from "is-unicode-supported" | ||
import color from "picocolors" | ||
|
||
const unicode = isUnicodeSupported() | ||
const s = (c: string, fallback: string) => (unicode ? c : fallback) | ||
|
||
export const S = { | ||
STEP_ACTIVE: s("◆", "*"), | ||
STEP_CANCEL: s("■", "x"), | ||
STEP_ERROR: s("▲", "x"), | ||
STEP_SUBMIT: s("◇", "o"), | ||
BAR_START: s("┌", "T"), | ||
BAR: s("│", "|"), | ||
BAR_END: s("└", "—"), | ||
RADIO_ACTIVE: s("●", ">"), | ||
RADIO_INACTIVE: s("○", " "), | ||
CHECKBOX_ACTIVE: s("◻", "[•]"), | ||
CHECKBOX_SELECTED: s("◼", "[+]"), | ||
CHECKBOX_INACTIVE: s("◻", "[ ]"), | ||
PASSWORD_MASK: s("▪", "•"), | ||
BAR_H: s("─", "-"), | ||
CORNER_TOP_RIGHT: s("╮", "+"), | ||
CONNECT_LEFT: s("├", "+"), | ||
CORNER_BOTTOM_RIGHT: s("╯", "+"), | ||
INFO: s("●", "•"), | ||
SUCCESS: s("◆", "*"), | ||
WARN: s("▲", "!"), | ||
ERROR: s("■", "x"), | ||
} | ||
|
||
export const symbol = (state: State) => { | ||
switch (state) { | ||
case "initial": | ||
case "active": | ||
return color.cyan(S.STEP_ACTIVE) | ||
case "cancel": | ||
return color.red(S.STEP_CANCEL) | ||
case "error": | ||
return color.yellow(S.STEP_ERROR) | ||
case "submit": | ||
return color.green(S.STEP_SUBMIT) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { TextPrompt } from "@clack/core" | ||
import c from "picocolors" | ||
import { S, symbol } from "./symbols" | ||
import type { TextOptions } from "./types" | ||
|
||
export function Text(opts: TextOptions) { | ||
return new TextPrompt({ | ||
validate: opts.validate, | ||
placeholder: opts.placeholder, | ||
defaultValue: opts.defaultValue, | ||
initialValue: opts.initialValue, | ||
render() { | ||
const title = `${c.gray(S.BAR)}\n${symbol(this.state)} ${opts.message}\n` | ||
|
||
const placeholder = opts.placeholder | ||
? c.inverse(opts.placeholder[0]) + c.dim(opts.placeholder.slice(1)) | ||
: c.inverse(c.hidden("_")) | ||
|
||
const value = !this.value ? placeholder : this.valueWithCursor | ||
|
||
switch (this.state) { | ||
case "error": | ||
return ( | ||
`${title.trim()}\n${c.yellow(S.BAR)} ${value}\n` + | ||
`${c.yellow(S.BAR_END)} ${c.yellow(this.error)}\n` | ||
) | ||
|
||
case "submit": | ||
return `${title}${c.gray(S.BAR)} ${c.dim(this.value || opts.placeholder)}` | ||
|
||
case "cancel": { | ||
const canceledValue = c.strikethrough(c.dim(this.value ?? "")) | ||
const hasTrimmedValue = this.value?.trim() | ||
return ( | ||
`${title}${c.gray(S.BAR)} ${canceledValue}` + | ||
`${hasTrimmedValue ? `\n${c.gray(S.BAR)}` : ""}` | ||
) | ||
} | ||
|
||
default: | ||
return `${title}${c.cyan(S.BAR)} ${value}\n${c.cyan(S.BAR_END)}\n` | ||
} | ||
}, | ||
}).prompt() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type TextOptions = { | ||
message: string | ||
placeholder?: string | ||
defaultValue?: string | ||
initialValue?: string | ||
validate?: (value: string) => string | void | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters