-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: text-field headless * feat: add textfield example in stackflow-spa * chore: delete .gitignore * chore: textfield test * feat: more test, handle onChange logic when maxLength * Create vitest.workspace.ts * chore: yarn * chore: change names * chore: test * chore: change test naem
- Loading branch information
1 parent
36de8f5
commit 0849de7
Showing
17 changed files
with
682 additions
and
21 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
Binary file not shown.
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
14 changes: 14 additions & 0 deletions
14
examples/stackflow-spa/src/activities/ActivityTextField.tsx
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,14 @@ | ||
import type { ActivityComponentType } from "@stackflow/react"; | ||
|
||
import { AppScreen } from "@stackflow/plugin-basic-ui"; | ||
import { TextField } from "../design-system/components"; | ||
|
||
const ActivityTextField: ActivityComponentType = () => { | ||
return ( | ||
<AppScreen appBar={{ title: "TextField" }}> | ||
<TextField variant="outlined" /> | ||
</AppScreen> | ||
); | ||
}; | ||
|
||
export default ActivityTextField; |
120 changes: 120 additions & 0 deletions
120
examples/stackflow-spa/src/design-system/components/TextField.tsx
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,120 @@ | ||
import clsx from "clsx"; | ||
import * as React from "react"; | ||
import { useTextField, type UseTextFieldProps } from "@seed-design/react-text-field"; | ||
|
||
import type { Assign } from "../util/types"; | ||
|
||
// TODO: Change | ||
// import "@seed-design/stylesheet/textfield.css"; | ||
|
||
export interface TextFieldProps | ||
extends Assign< | ||
Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "prefix" | "suffix">, | ||
UseTextFieldProps | ||
> { | ||
/** | ||
* @default "medium" | ||
*/ | ||
size?: "small" | "medium" | "large"; | ||
|
||
/** | ||
* @default "outlined" | ||
*/ | ||
variant: "outlined" | "underlined"; | ||
|
||
requiredIndicator?: string; | ||
|
||
optionalIndicator?: string; | ||
|
||
prefix?: React.ReactNode; | ||
|
||
suffix?: React.ReactNode; | ||
|
||
label?: string; | ||
|
||
description?: string; | ||
|
||
errorMessage?: string; | ||
|
||
hideCharacterCount?: boolean; | ||
} | ||
|
||
export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => { | ||
const { | ||
className, | ||
size = "medium", | ||
variant = "outlined", | ||
requiredIndicator, | ||
optionalIndicator, | ||
prefix, | ||
suffix, | ||
label, | ||
description, | ||
errorMessage, | ||
hideCharacterCount, | ||
maxLength, | ||
} = props; | ||
const { | ||
rootProps, | ||
inputProps, | ||
labelProps, | ||
descriptionProps, | ||
errorMessageProps, | ||
stateProps, | ||
restProps, | ||
isInvalid, | ||
isRequired, | ||
graphemes, | ||
} = useTextField({ ...props, elementType: "input" }); | ||
|
||
const showErrorMessage = isInvalid && !!errorMessage; | ||
const indicator = isRequired ? requiredIndicator : optionalIndicator; | ||
const showHint = !!description || (errorMessage && isInvalid); | ||
const renderCharacterCount = !hideCharacterCount && maxLength; | ||
const renderFoot = showHint || renderCharacterCount; | ||
const renderHead = label || indicator; | ||
|
||
return ( | ||
<div className={clsx(className)} {...stateProps} {...rootProps}> | ||
{renderHead && ( | ||
<div data-part="head"> | ||
{label && <label {...labelProps}>{label}</label>} | ||
{indicator && <span data-part="indicator">{indicator}</span>} | ||
</div> | ||
)} | ||
<div data-part="field"> | ||
{prefix && ( | ||
<div data-part="prefix"> | ||
{typeof prefix === "string" ? <span>{prefix}</span> : prefix} | ||
</div> | ||
)} | ||
<input ref={ref} {...inputProps} {...restProps} /> | ||
{suffix && ( | ||
<div data-part="suffix"> | ||
{typeof suffix === "string" ? <span>{suffix}</span> : suffix} | ||
</div> | ||
)} | ||
</div> | ||
{renderFoot && ( | ||
<div data-part="foot"> | ||
{showErrorMessage ? ( | ||
<span {...stateProps} {...errorMessageProps}> | ||
{errorMessage && errorMessage} | ||
</span> | ||
) : ( | ||
<span {...stateProps} {...descriptionProps}> | ||
{description} | ||
</span> | ||
)} | ||
{renderCharacterCount && ( | ||
<div {...stateProps} data-part="count-container"> | ||
<span data-part="character-count">{graphemes.length}</span> | ||
<span data-part="max-count">/{maxLength}</span> | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}); | ||
TextField.displayName = "TextField"; |
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 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,47 @@ | ||
{ | ||
"name": "@seed-design/react-text-field", | ||
"version": "0.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/daangn/seed-design.git", | ||
"directory": "packages/react-headless/text-field" | ||
}, | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"require": "./lib/index.js", | ||
"import": "./lib/index.mjs" | ||
} | ||
}, | ||
"main": "./lib/index.js", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"prepack": "rm -rf lib && yarn build", | ||
"build": "nanobundle build" | ||
}, | ||
"dependencies": { | ||
"@radix-ui/react-use-controllable-state": "1.0.1", | ||
"@seed-design/dom-utils": "0.0.0", | ||
"unicode-segmenter": "^0.7.0" | ||
}, | ||
"devDependencies": { | ||
"nanobundle": "^1.6.0" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=18.0.0", | ||
"react-dom": ">=18.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"ultra": { | ||
"concurrent": [ | ||
"dev", | ||
"build" | ||
] | ||
} | ||
} |
Oops, something went wrong.