-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add SelectSearch #929
Merged
Merged
Add SelectSearch #929
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ecb84ef
Add SelectSearch
Oksamies 6ec150c
Cleanup ZodRawShape imports
Oksamies 71649da
Change form error messages to divs from spans
Oksamies 972d120
Fix SelectSearch option filtering
Oksamies 035d7d3
Revert form component error element type change
Oksamies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
apps/cyberstorm-storybook/stories/components/SelectSearch.stories.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,59 @@ | ||
import { StoryFn, Meta } from "@storybook/react"; | ||
import React, { useState } from "react"; | ||
import { SelectSearch } from "@thunderstore/cyberstorm/src/components/SelectSearch/SelectSearch"; | ||
|
||
const meta = { | ||
title: "Cyberstorm/Components/SelectSearch", | ||
component: SelectSearch, | ||
} as Meta<typeof SelectSearch>; | ||
|
||
const options = [ | ||
"Team 1", | ||
"Team 2", | ||
"Team 3", | ||
"Team 4", | ||
"Team 5", | ||
"Team 6", | ||
"Team 7", | ||
"Team 8", | ||
"Team 9", | ||
"Team 10", | ||
"Team 11", | ||
"Team 12", | ||
"Team 13", | ||
"Team 14", | ||
]; | ||
|
||
const defaultArgs = { | ||
placeholder: "Select something", | ||
options: options, | ||
}; | ||
|
||
const Template: StoryFn<typeof SelectSearch> = (args) => { | ||
const [selected, setSelected] = useState<string | undefined>(undefined); | ||
const defaultProps = { | ||
...args, | ||
onChange: setSelected, | ||
value: selected, | ||
}; | ||
return ( | ||
<div> | ||
<div style={{ color: "white" }}>Value in state: {selected}</div> | ||
<SelectSearch {...defaultProps} /> | ||
</div> | ||
); | ||
}; | ||
|
||
const GreenSelectSearch = Template.bind({}); | ||
GreenSelectSearch.args = { | ||
...defaultArgs, | ||
color: "green", | ||
}; | ||
|
||
const RedSelectSearch = Template.bind({}); | ||
RedSelectSearch.args = { | ||
...defaultArgs, | ||
color: "red", | ||
}; | ||
|
||
export { meta as default, GreenSelectSearch, RedSelectSearch }; |
43 changes: 43 additions & 0 deletions
43
packages/cyberstorm-forms/src/components/FormSelectSearch.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,43 @@ | ||
"use client"; | ||
|
||
import { z, ZodObject, ZodRawShape } from "zod"; | ||
import { Path, useController } from "react-hook-form"; | ||
import { SelectSearch } from "@thunderstore/cyberstorm"; | ||
import styles from "./FormTextInput.module.css"; | ||
|
||
export type FormSelectSearchProps< | ||
Schema extends ZodObject<Z>, | ||
Z extends ZodRawShape | ||
> = { | ||
// The schema is required to allow TS to infer valid values for the name field | ||
schema: Schema; | ||
name: Path<z.infer<Schema>>; | ||
placeholder?: string; | ||
options: string[]; | ||
}; | ||
export function FormSelectSearch< | ||
Schema extends ZodObject<Z>, | ||
Z extends ZodRawShape | ||
>({ name, placeholder, options }: FormSelectSearchProps<Schema, Z>) { | ||
const { | ||
field, | ||
fieldState: { isDirty, invalid, error }, | ||
formState: { isSubmitting, disabled }, | ||
} = useController({ name }); | ||
|
||
return ( | ||
<> | ||
<SelectSearch | ||
{...field} | ||
ref={field.ref} | ||
placeholder={placeholder} | ||
color={isDirty || invalid ? (invalid ? "red" : "green") : undefined} | ||
disabled={isSubmitting || disabled} | ||
options={options} | ||
/> | ||
{error && <span className={styles.errorMessage}>{error.message}</span>} | ||
</> | ||
); | ||
} | ||
|
||
FormSelectSearch.displayName = "FormSelectSearch"; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { useFormToaster } from "./useFormToaster"; | ||
export { FormSubmitButton } from "./components/FormSubmitButton"; | ||
export { FormSelectSearch } from "./components/FormSelectSearch"; | ||
export { FormTextInput } from "./components/FormTextInput"; | ||
export { CreateTeamForm } from "./forms/CreateTeamForm"; |
141 changes: 141 additions & 0 deletions
141
packages/cyberstorm/src/components/SelectSearch/SelectSearch.module.css
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,141 @@ | ||
.root { | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--gap--16); | ||
justify-content: flex-end; | ||
width: auto; | ||
min-height: 6rem; | ||
color: var(--color-text--tertiary); | ||
} | ||
|
||
.selected { | ||
display: flex; | ||
flex-flow: row wrap; | ||
gap: var(--space--8); | ||
} | ||
|
||
.search { | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
width: auto; | ||
height: 2.75rem; | ||
color: var(--color-text--tertiary); | ||
} | ||
|
||
.inputContainer { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
width: 100%; | ||
border: var(--border-width--2) solid var(--border-color); | ||
|
||
border-radius: var(--border-radius--8); | ||
background-color: var(--color-surface--4); | ||
|
||
--border-color: transparent; | ||
|
||
transition: ease-out 300ms; | ||
} | ||
|
||
.input { | ||
width: 100%; | ||
margin: var(--space--10) var(--space--14); | ||
font-weight: var(--font-weight-medium); | ||
font-size: var(--font-size--l); | ||
line-height: normal; | ||
background-color: transparent; | ||
} | ||
|
||
.inputContainer:hover { | ||
--border-color: var(--color-border--highlight); | ||
} | ||
|
||
.inputContainer:focus-within { | ||
color: var(--color-text--default); | ||
background-color: var(--color-black); | ||
|
||
--border-color: var(--color-border--highlight); | ||
} | ||
|
||
.input::placeholder { | ||
color: var(--color-text--tertiary); | ||
} | ||
|
||
.inputContainer[data-color="red"] { | ||
--border-color: var(--color-red--5); | ||
} | ||
|
||
.inputContainer[data-color="red"]:hover { | ||
--border-color: var(--color-red--3); | ||
} | ||
|
||
.inputContainer[data-color="green"] { | ||
--border-color: var(--color-cyber-green--50); | ||
} | ||
|
||
.inputContainer[data-color="green"]:hover { | ||
--border-color: var(--color-cyber-green--80); | ||
} | ||
|
||
.clearSearch { | ||
width: 3rem; | ||
height: 100%; | ||
color: #c6c3ff; | ||
background: transparent; | ||
opacity: 0.5; | ||
} | ||
|
||
.showMenuButton { | ||
width: 3rem; | ||
height: 100%; | ||
color: #9c9cc4; | ||
background: transparent; | ||
} | ||
|
||
.inputButtonDivider { | ||
width: 0.063rem; | ||
height: 1.375rem; | ||
background: #4343a3; | ||
} | ||
|
||
.menu { | ||
position: absolute; | ||
top: 3.25rem; | ||
z-index: 9999; | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--gap--4); | ||
width: 100%; | ||
min-height: 1.5rem; | ||
max-height: 12rem; | ||
padding: var(--space--8) 0; | ||
border: var(--space--px) var(--color-surface--6) solid; | ||
border-radius: var(--border-radius--8); | ||
overflow: hidden; | ||
overflow-y: auto !important; | ||
color: var(--text-color); | ||
background-color: var(--color-surface--2); | ||
box-shadow: var(--box-shadow-default); | ||
visibility: hidden; | ||
|
||
--text-color: var(--color-white); | ||
--bg-color: var(--color-surface--4); | ||
} | ||
|
||
.menu:where(.visible) { | ||
visibility: visible; | ||
} | ||
|
||
.menuLabel { | ||
font-weight: var(--font-weight-medium); | ||
} | ||
|
||
.multiSelectItemWrapper { | ||
padding: var(--space--12) var(--space--16); | ||
} | ||
|
||
.multiSelectItemWrapper:focus { | ||
background-color: var(--color-surface--6); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use div here? E.g. with flex the error span can get placed oddly. Just thinking aloud here, not sure if it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant replacing this
<>
fragment with a div, not the<span>
inside. Now all the potential problems apply to that<div>
as well since it's going to be rendered as a sibling to the<SelectSearch>