-
Notifications
You must be signed in to change notification settings - Fork 0
finished inputs #8
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
Open
Chaitya2108
wants to merge
8
commits into
main
Choose a base branch
from
chaitya/inputs-dropdowns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5465098
finished buttons
Chaitya2108 716dff2
hi
alexzhang1618 7e0d91a
update directory
alexzhang1618 863ee94
hi'
alexzhang1618 8cbe7ca
hi
alexzhang1618 9dd55f9
messing around with stuff
alexzhang1618 6ce02fd
run it back
alexzhang1618 4c5e8cb
feedback on inputs
Chaitya2108 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
This file contains hidden or 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,31 @@ | ||
# .github/workflows/preview.yml | ||
name: Deploy PR previews | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- closed | ||
|
||
concurrency: preview-${{ github.ref }} | ||
|
||
jobs: | ||
deploy-preview: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install and Build | ||
if: github.event.action != 'closed' # You might want to skip the build if the PR has been closed | ||
run: | | ||
npm install | ||
npm run build-storybook | ||
|
||
- name: Deploy preview | ||
uses: rossjrw/pr-preview-action@v1 | ||
with: | ||
source-dir: ./storybook-static/ | ||
preview-branch: gh-pages |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
.cache | ||
.next | ||
storybook-static | ||
dist | ||
dist | ||
package-lock.json |
This file contains hidden or 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,81 @@ | ||
.dropdown-wrapper { | ||
font-family: sans-serif; | ||
width: 291px; | ||
user-select: none; | ||
position: relative; | ||
overflow: visible; | ||
/* padding: 10px 20px 10px 20px; */ | ||
|
||
font-family: "DM Sans", sans-serif; | ||
} | ||
|
||
/* Button part (closed or open) */ | ||
.dropdown-header { | ||
width: 100%; | ||
padding: 10px 20px; | ||
border-bottom: none; | ||
font-size: 16px; | ||
height: 67px; | ||
border: 1px solid black; | ||
border-radius: 16px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
cursor: pointer; | ||
background-color: white; | ||
} | ||
|
||
.dropdown-wrapper.open .dropdown-header { | ||
border-radius: 16px 16px 0 0; | ||
/* border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; */ | ||
} | ||
|
||
/* Arrow */ | ||
.arrow { | ||
width: 24px; | ||
height: 24px; | ||
flex-shrink: 0px; | ||
} | ||
|
||
/* Dropdown menu */ | ||
.dropdown-menu { | ||
position: absolute; | ||
top: 100%; | ||
left: 0; | ||
padding: 0px 20px 10px 20px; | ||
width: 100%; | ||
margin: 0; | ||
display: flex; | ||
list-style: none; | ||
flex-direction: column; | ||
gap: 10px; | ||
background-color: white; | ||
border: 1px solid black; | ||
/* border-top: none; */ | ||
border-radius: 0 0 12px 12px; | ||
|
||
z-index: 10; | ||
} | ||
|
||
/* Divider between header and options | ||
.dropdown-menu::before { | ||
content: ''; | ||
display: block; | ||
height: 1px; | ||
background-color: black; | ||
margin-bottom: 8px; | ||
} */ | ||
|
||
/* Each option */ | ||
.dropdown-item { | ||
line-height: 24px; | ||
font-size: 16px; | ||
border-radius: 8px; | ||
padding: 4px 8px; | ||
cursor: pointer; | ||
} | ||
|
||
.dropdown-item:hover { | ||
background-color: #f5f5f5; | ||
} |
This file contains hidden or 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,49 @@ | ||
import React, {useState} from 'react'; | ||
import './dropdown.css'; | ||
|
||
export interface DropdownProps { | ||
theme?: 'light' | 'dark'; | ||
size?: 'desktop' | 'mobile'; | ||
suggestions?: string[]; | ||
onChange?: (value: string) => void; | ||
} | ||
|
||
export const Dropdown: React.FC<DropdownProps> = ({ | ||
theme = 'light', | ||
size = "desktop", | ||
suggestions = [], | ||
onChange | ||
|
||
}) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [selected, setIsSelected] = useState<string | null>(null); | ||
// const options = {[...(selected ? [selected] : []), ...suggestions.filter(s => s !== selected)]}; | ||
// const filtered = selected ? suggestions.filter(s => s !== selected) : suggestions; | ||
const options = [...suggestions].sort((a, b) => a.localeCompare(b)); | ||
const toggleDropdown = () => setIsOpen(!isOpen); | ||
const handleSelect = (option: string) => { | ||
setIsSelected(option); | ||
setIsOpen(false); | ||
onChange?.(option); | ||
} | ||
|
||
return ( | ||
<div className={`dropdown-wrapper ${theme} ${size}`}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should probably also have a |
||
<div className="dropdown-header" onClick={toggleDropdown}> | ||
<span>{selected ?? 'Select an option'}</span> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="25" viewBox="0 0 24 25" fill="none"> | ||
<path d="M16.59 9.09L12 13.67L7.41 9.09L6 10.5L12 16.5L18 10.5L16.59 9.09Z" fill="black"/> | ||
</svg> | ||
</div> | ||
{isOpen && ( | ||
<ul className="dropdown-menu"> | ||
{options.map((option, i) => ( | ||
<li key={i} className="dropdown-item" onClick={() => handleSelect(option)}> | ||
{option} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains hidden or 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,66 @@ | ||
import React, { useState, useRef } from 'react'; | ||
import './inputs.css' | ||
|
||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> { | ||
theme?: 'light' | 'dark'; // Define theme prop | ||
variant?: 'primary' | 'error'; | ||
inputSize?: 'desktop' | 'mobile'; | ||
suggestions?: string[]; | ||
onValueChange?: (value: string) => void; | ||
|
||
} | ||
|
||
export const Input: React.FC<InputProps> = ({ | ||
Chaitya2108 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
theme = "light", | ||
variant = 'primary', | ||
inputSize = 'desktop', | ||
suggestions = [], | ||
onValueChange, | ||
...rest | ||
}) => { | ||
const [value, setValue]= useState(''); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const bestSuggestion = suggestions.find(s => | ||
s.toLowerCase().startsWith(value.toLowerCase()) && s.toLowerCase() !== value.toLowerCase()) | ||
|| ''; | ||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const newVal = e.target.value; | ||
setValue(newVal); | ||
onValueChange?.(newVal); | ||
}; | ||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if ((e.key === 'ArrowRight' || e.key === 'Tab') && bestSuggestion) { | ||
e.preventDefault(); | ||
setValue(bestSuggestion); | ||
onValueChange?.(bestSuggestion); | ||
|
||
} | ||
} | ||
return ( | ||
|
||
<div className={`inline-suggest-wrapper ${inputSize}`}> | ||
<input | ||
ref={inputRef} | ||
className={`input ${theme} ${variant} ${inputSize}`} | ||
value={value} | ||
onChange={handleChange} | ||
onKeyDown={handleKeyDown} | ||
{...rest} | ||
/> | ||
{value && bestSuggestion && ( | ||
<div className={`inline-suggestion ${theme}`}> | ||
<span>{value}</span> | ||
<span className="hint" | ||
onClick={() => { | ||
setValue(bestSuggestion); | ||
onValueChange?.(bestSuggestion); | ||
inputRef.current?.focus(); // optional: put focus back in input | ||
}} | ||
>{bestSuggestion.slice(value.length)}</span> | ||
</div> | ||
)} | ||
</div> | ||
|
||
); | ||
} |
This file contains hidden or 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,94 @@ | ||
|
||
.inline-suggest-wrapper { | ||
position: relative; | ||
display: inline-block; | ||
width: 291px; /* match input width */ | ||
font-family: "DM Sans", sans-serif; | ||
} | ||
|
||
.inline-suggest-wrapper.desktop { | ||
font-size: 1.125rem; /* match .input.desktop */ | ||
line-height: 1.5rem; /* match .input.desktop */ | ||
} | ||
.inline-suggest-wrapper.mobile { | ||
font-size: 1rem; | ||
line-height: 1.3125rem; | ||
} | ||
|
||
.inline-suggestion { | ||
top: 50%; | ||
position: absolute; | ||
transform: translateY(-50%); | ||
pointer-events: none; | ||
left: 0; | ||
box-sizing: border-box; | ||
/* padding: 10px 20px 10px 20px; */ | ||
padding: 0 20px; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
font-family: inherit; | ||
font-weight: 400; | ||
font-size: inherit; | ||
line-height: inherit; | ||
white-space: pre; | ||
} | ||
.inline-suggestion .hint { | ||
pointer-events: auto; | ||
cursor: pointer; | ||
} | ||
.inline-suggestion span:first-child { | ||
color: transparent; | ||
user-select: none; | ||
} | ||
.inline-suggestion.light { | ||
color: var(--Surface-Elevation-border, #979797); | ||
} | ||
.inline-suggestion.dark { | ||
color: #797C8B; | ||
} | ||
.input { | ||
position: relative; | ||
width: 291px; | ||
border-radius: 16px; | ||
justify-content: space-between; | ||
padding: 10px 20px 10px 20px; | ||
font-family: "DM Sans", sans-serif; | ||
font-weight: 400; | ||
box-sizing: border-box; | ||
letter-spacing: 0; | ||
vertical-align: middle; | ||
} | ||
|
||
|
||
.input.light { | ||
background-color: #FBFBFB; | ||
|
||
} | ||
|
||
.input.dark { | ||
background-color: #2F3037; | ||
color: var(--Surface-Text-color-text-color, #FFFFFF); | ||
|
||
} | ||
|
||
.input.primary { | ||
border: 1px solid var(--Buttons-CTA-Button-Secondary-secondary-text, #000000); | ||
} | ||
|
||
.input.error { | ||
border: 1px solid #E36370; | ||
color: #E36370; | ||
} | ||
|
||
.input.desktop { | ||
font-size: 1.125rem; | ||
line-height: 1.5e; | ||
height: 67px; | ||
} | ||
|
||
.input.mobile { | ||
font-size: 1rem; | ||
line-height: 1.3125rem; | ||
height: 58px; | ||
} |
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.
dropdown looks too tall
maybe missing
box-sizing: border-box
?