-
Notifications
You must be signed in to change notification settings - Fork 1
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
募金登録の金額入力フォームにプルダウンを追加する #659
Changes from 5 commits
0048bf3
04572cd
2c34d4a
9ea1599
02bfca5
6fec28d
2d6851e
4e8efc8
946c425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,23 +11,36 @@ interface Props { | |||||||||
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||||||||||
children?: React.ReactNode; | ||||||||||
type?: string; | ||||||||||
datalist?: { id: number; name: string }[]; | ||||||||||
listKey?: string; | ||||||||||
enableDatalist?: boolean; | ||||||||||
} | ||||||||||
|
||||||||||
function Input(props: Props): JSX.Element { | ||||||||||
const className = | ||||||||||
'rounded-full border border-primary-1 py-2 px-4' + | ||||||||||
(props.className ? ` ${props.className}` : ''); | ||||||||||
return ( | ||||||||||
<input | ||||||||||
className={clsx(s.input, className)} | ||||||||||
placeholder={props.placeholder} | ||||||||||
id={props.id} | ||||||||||
value={props.value} | ||||||||||
onChange={props.onChange} | ||||||||||
type={props.type} | ||||||||||
> | ||||||||||
{props.children} | ||||||||||
</input> | ||||||||||
<div> | ||||||||||
<input | ||||||||||
className={clsx(s.input, className)} | ||||||||||
placeholder={props.placeholder} | ||||||||||
id={props.id} | ||||||||||
value={props.value} | ||||||||||
onChange={props.onChange} | ||||||||||
type={props.type} | ||||||||||
list={props.enableDatalist ? props.listKey : undefined} | ||||||||||
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.
Suggested change
listにはpropsにdatalistがあれば、props.listkeyを渡すで十分かと思います。 |
||||||||||
> | ||||||||||
{props.children} | ||||||||||
</input> | ||||||||||
{props.enableDatalist && ( | ||||||||||
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.
Suggested change
props.datalistがあるかどうかで判断できるかなって思います。 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.
Suggested change
|
||||||||||
<datalist id={props.listKey}> | ||||||||||
{props.datalist?.map((option) => ( | ||||||||||
<option key={option.id} value={option.name} /> | ||||||||||
))} | ||||||||||
</datalist> | ||||||||||
)} | ||||||||||
</div> | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ import { Modal, CloseButton, Input, Select, PrimaryButton } from '../common'; | |||||||
import { userAtom } from '@/store/atoms'; | ||||||||
import { post } from '@api/fundInformations'; | ||||||||
import { BUREAUS } from '@constants/bureaus'; | ||||||||
import { DONATION_AMOUNT } from '@constants/donationAmount'; | ||||||||
import { Department, FundInformation, Teacher, User } from '@type/common'; | ||||||||
|
||||||||
interface ModalProps { | ||||||||
|
@@ -132,7 +133,14 @@ const OpenAddModal: FC<ModalProps> = (props) => { | |||||||
</div> | ||||||||
<p className='col-span-1 text-black-600'>金額</p> | ||||||||
<div className='col-span-4 w-full'> | ||||||||
<Input className='w-full' value={formData.price} onChange={handler('price')} /> | ||||||||
<Input | ||||||||
className='w-full' | ||||||||
value={formData.price} | ||||||||
onChange={handler('price')} | ||||||||
datalist={DONATION_AMOUNT} | ||||||||
listKey='amoutOptions' | ||||||||
enableDatalist={true} | ||||||||
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.
Suggested change
上のように修正すれば消せます。 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. ちなみにtrueを渡さなくても
Suggested change
のみでtrueのように動作します |
||||||||
/> | ||||||||
</div> | ||||||||
<p className='col-span-1 text-black-600'>備考</p> | ||||||||
<div className='col-span-4 w-full'> | ||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import { Dispatch, SetStateAction, useEffect, useState, useMemo } from 'react'; | |||
import { Modal, Input, Select, CloseButton, PrimaryButton } from '../common'; | ||||
import { put } from '@api/fundInformations'; | ||||
import { BUREAUS } from '@constants/bureaus'; | ||||
import { DONATION_AMOUNT } from '@constants/donationAmount'; | ||||
import { FundInformation, Teacher, User, Department } from '@type/common'; | ||||
|
||||
interface ModalProps { | ||||
|
@@ -140,7 +141,14 @@ export default function EditModal(props: ModalProps) { | |||
</div> | ||||
<p className='col-span-1 text-black-600'>金額</p> | ||||
<div className='col-span-4 w-full'> | ||||
<Input className='w-full' value={formData.price} onChange={handler('price')} /> | ||||
<Input | ||||
className='w-full' | ||||
value={formData.price} | ||||
onChange={handler('price')} | ||||
datalist={DONATION_AMOUNT} | ||||
listKey='amoutOptions' | ||||
enableDatalist={true} | ||||
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.
Suggested change
ここも同様です。 |
||||
/> | ||||
</div> | ||||
<p className='col-span-1 text-black-600'>備考</p> | ||||
<div className='col-span-4 w-full'> | ||||
|
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. constantで定数を定義できてて良いと思います! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const DONATION_AMOUNT = [ | ||
{ | ||
id: 1, | ||
name: '1000', | ||
}, | ||
{ | ||
id: 2, | ||
name: '2000', | ||
}, | ||
{ | ||
id: 3, | ||
name: '5000', | ||
}, | ||
{ | ||
id: 4, | ||
name: '10000', | ||
}, | ||
]; |
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.
好みですが、個人的にはdalalistがあるかどうかで判断できるかなって思いました。
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.
datalist
とlistkey
の存在を同時に確かめたい場合は、一緒にしてしまってもいいと思います