Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for outputting d.ts files for Inputs #238

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist/
node_modules/
scratch/
types/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"module-alias": "2",
"rollup": "2",
"rollup-plugin-terser": "7",
"snowpack": "3"
"snowpack": "3",
"typescript": "^4.8.3"
},
"dependencies": {
"htl": "0.3",
Expand Down
33 changes: 33 additions & 0 deletions src/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,43 @@ export function number(extent, options) {
return createRange({extent}, options);
}

/**
* @typedef {{ label: string, step: number, format: (d: number) => string,
* placeholder: string, transform: (d: number) => number, invert: (d: number)
* => number, validate: (d: number) => boolean, value: number, width: number,
* disabled: boolean }} Options
*/

/**
* A Range input specifies a number between the given *extent* = [*min*, *max*]
* (inclusive). If an *extent* is not specified, it defaults to [0, 1]. The
* chosen number can be adjusted roughly with a slider, or precisely by typing a
* number.
*
* The available *options* are:
*
* * *label* - a label; either a string or an HTML element.
* * *step* - the step (precision); the interval between adjacent values.
* * *format* - a format function; defaults to [formatTrim](#formatTrim).
* * *placeholder* - a placeholder string for when the input is empty.
* * *transform* - an optional non-linear transform.
* * *invert* - the inverse transform.
* * *validate* - a function to check whether the number input is valid.
* * *value* - the initial value; defaults to (*min* + *max*) / 2.
* * *width* - the width of the input (not including the label).
* * *disabled* - whether input is disabled; defaults to false.
*
* @param {[number, number]} extent
* @param {Options} options
* @returns Element
*/
export function range(extent = [0, 1], options) {
return createRange({extent, range: true}, options);
}

/**
* @returns Element
*/
function createRange({
extent: [min, max],
range
Expand Down
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["esnext", "dom"],
"strict": true,
"stripInternal": true,
"outDir": "dist",
"allowJs": true,
"declaration": true,
"declarationDir": "types",
"resolveJsonModule": true,
"moduleResolution": "node",
"paths": {
"@observablehq/inputs": ["./src/index.js"]
}
},
"include": ["src/**/*"]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3857,6 +3857,11 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.8.3:
version "4.8.3"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.8.3.tgz#d59344522c4bc464a65a730ac695007fdb66dd88"
integrity sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==

unique-filename@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/unique-filename/-/unique-filename-1.1.1.tgz#1d69769369ada0583103a1e6ae87681b56573230"
Expand Down