-
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.
### Description - Adds `<Select/>` component. A simpler version of `<Combobox/>` that more closely matches the browser `<select/>` element. - Support the `multiple` prop like the browser `<select/>` - Fixes [KNO-6849](https://linear.app/knock/issue/KNO-6849/[telegraph]-allow-combobox-labels-to-be-react-nodes) so that we can pass react nodes to the label. - Fixes [KNO-6934](https://linear.app/knock/issue/KNO-6934/[telegraph]-allow-disabled-state-without-type-error-on-combobox) so that we can pass the `disabled` prop to the select component and combobox component. ### Tasks [KNO-7249](https://linear.app/knock/issue/KNO-7249/[telegraph]-select-component) [KNO-6934](https://linear.app/knock/issue/KNO-6934/[telegraph]-allow-disabled-state-without-type-error-on-combobox) [KNO-6849](https://linear.app/knock/issue/KNO-6849/[telegraph]-allow-combobox-labels-to-be-react-nodes)
- Loading branch information
Showing
16 changed files
with
378 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@telegraph/combobox": patch | ||
"@telegraph/select": patch | ||
--- | ||
|
||
new select component + combobox fixes |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
"@knocklabs/eslint-config/library.js", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:react-hooks/recommended", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
}; |
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,17 @@ | ||
![Telegraph by Knock](https://github.com/knocklabs/telegraph/assets/29106675/9b5022e3-b02c-4582-ba57-3d6171e45e44) | ||
|
||
[![npm version](https://img.shields.io/npm/v/@telegraph/button.svg)](https://www.npmjs.com/package/@telegraph/select) | ||
|
||
# @telegraph/select | ||
> A simple select component built on top of @telegraph/combobox | ||
## Installation Instructions | ||
|
||
``` | ||
npm install @telegraph/select | ||
``` | ||
|
||
### Add stylesheet | ||
``` | ||
@import "@telegraph/select" | ||
``` |
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,53 @@ | ||
{ | ||
"name": "@telegraph/select", | ||
"version": "0.0.0", | ||
"description": "A simple select component built on top of @telegraph/combobox", | ||
"repository": "https://github.com/knocklabs/telegraph/tree/main/packages/select", | ||
"author": "@knocklabs", | ||
"license": "MIT", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.mjs", | ||
"types": "./dist/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/esm/index.mjs", | ||
"require": "./dist/cjs/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"prettier": "@telegraph/prettier-config", | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"dev": "vite build --watch --emptyOutDir false", | ||
"build": "yarn clean && vite build", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write", | ||
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@telegraph/combobox": "workspace:*", | ||
"@telegraph/helpers": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@knocklabs/eslint-config": "^0.0.3", | ||
"@knocklabs/typescript-config": "^0.0.2", | ||
"@telegraph/postcss-config": "workspace:^", | ||
"@telegraph/prettier-config": "workspace:^", | ||
"@telegraph/vite-config": "workspace:^", | ||
"@types/react": "^18.2.48", | ||
"eslint": "^8.56.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.3.1", | ||
"typescript": "^5.5.4", | ||
"vite": "^5.3.6" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
} | ||
} |
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 pkg from "@telegraph/postcss-config"; | ||
|
||
const { styleEnginePostCssConfig } = pkg; | ||
|
||
export default styleEnginePostCssConfig; |
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,72 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
|
||
import { Select } from "./Select"; | ||
|
||
const meta = { | ||
title: "Components/Select", | ||
component: Select.Root, | ||
tags: ["autodocs"], | ||
argTypes: { | ||
size: { | ||
options: ["0", "1", "2", "3"], | ||
control: { | ||
type: "select", | ||
}, | ||
}, | ||
disabled: { | ||
control: { | ||
type: "boolean", | ||
}, | ||
}, | ||
}, | ||
args: { | ||
size: "2", | ||
disabled: false, | ||
}, | ||
} satisfies Meta<typeof Select.Root>; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export default meta; | ||
|
||
export const SingleSelect: Story = { | ||
render: (args) => { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const [value, setValue] = React.useState<string | undefined>(undefined); | ||
return ( | ||
<Select.Root | ||
placeholder="Select an option" | ||
value={value} | ||
onValueChange={setValue} | ||
size={args.size} | ||
disabled={args.disabled} | ||
> | ||
<Select.Option value="1">Option 1</Select.Option> | ||
<Select.Option value="2">Option 2</Select.Option> | ||
</Select.Root> | ||
); | ||
}, | ||
}; | ||
|
||
export const MultiSelect: Story = { | ||
render: (args) => { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const [value, setValue] = React.useState<Array<string>>([]); | ||
return ( | ||
<Select.Root | ||
placeholder="Select an option" | ||
value={value} | ||
onValueChange={setValue} | ||
size={args.size} | ||
multiple | ||
disabled={args.disabled} | ||
> | ||
<Select.Option value="1">Option 1</Select.Option> | ||
<Select.Option value="2">Option 2</Select.Option> | ||
<Select.Option value="3">Option 3</Select.Option> | ||
<Select.Option value="4">Option 4</Select.Option> | ||
</Select.Root> | ||
); | ||
}, | ||
}; |
Oops, something went wrong.