Skip to content

Commit

Permalink
feat: improve the interaction design of the DatetimePicker component
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteMinds committed May 19, 2023
1 parent ac9afe2 commit 97c1264
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/neuron-ui/src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ const Send = () => {
<div className={styles.datetimePicker}>
<div className={styles.datetimeDialog}>
<DatetimePicker
confirmText={(time, display) => `${t('send.release-on')}${time == null ? '' : display}`}
onConfirm={(time: number) => {
updateTransactionOutput('date')(locktimeIndex)(`${time}`)
setLocktimeIndex(-1)
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/styles/mixin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

@mixin dialog-confirm-button {
border: none;
width: 5.125rem;
min-width: 5.125rem;
height: 1.875rem;
background-color: var(--nervos-green);
color: #fff;
Expand Down
26 changes: 13 additions & 13 deletions packages/neuron-ui/src/widgets/DatetimePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Button from 'widgets/Button'
import { useTranslation } from 'react-i18next'
import styles from './datetimePicker.module.scss'

const SECONDS_PER_DAY = 24 * 3600 * 1000
let UTC: string | number = -new Date().getTimezoneOffset() / 60
if (UTC > 0) {
UTC = `UTC+${UTC}`
Expand All @@ -14,10 +13,7 @@ if (UTC > 0) {

export const formatDate = (datetime: Date) => {
const month = (datetime.getMonth() + 1).toString().padStart(2, '0')
const date = datetime
.getDate()
.toString()
.padStart(2, '0')
const date = datetime.getDate().toString().padStart(2, '0')
const year = datetime.getFullYear()
return `${month}/${date}/${year}`
}
Expand All @@ -28,14 +24,9 @@ export interface DatetimePickerProps {
notice?: string
onConfirm: (time: number) => void
onCancel: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void
confirmText?: string | ((time?: number, display?: string) => string)
}
const DatetimePicker = ({
preset = new Date(Date.now() + SECONDS_PER_DAY),
onConfirm,
onCancel,
title,
notice,
}: DatetimePickerProps) => {
const DatetimePicker = ({ preset, onConfirm, onCancel, confirmText, title, notice }: DatetimePickerProps) => {
const [t] = useTranslation()
const [status, setStatus] = useState<'done' | 'edit'>('done')
const [display, setDisplay] = useState<string>(preset ? formatDate(new Date(+preset)) : '')
Expand Down Expand Up @@ -138,7 +129,16 @@ const DatetimePicker = ({
) : null}
<div className={styles.actions}>
<Button type="cancel" label={t('common.cancel')} onClick={onCancel} />
<Button type="submit" label={t('common.save')} onClick={onSubmit} disabled={disabled} />
<Button
type="submit"
label={
typeof confirmText === 'function'
? confirmText(selected?.getTime(), display)
: confirmText ?? t('common.save')
}
onClick={onSubmit}
disabled={disabled}
/>
</div>
</div>
</div>
Expand Down

0 comments on commit 97c1264

Please sign in to comment.