From 1eb038b94b81ff51f7ae841c1e69268edb8237fb Mon Sep 17 00:00:00 2001 From: Lingxi Li Date: Thu, 2 Jun 2022 17:19:22 -0400 Subject: [PATCH 01/14] [Input] Optimize `isValidOnBlur` regex algorithm. --- packages/date-picker/date-picker-input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/date-picker/date-picker-input.js b/packages/date-picker/date-picker-input.js index 376df69..d8ad358 100644 --- a/packages/date-picker/date-picker-input.js +++ b/packages/date-picker/date-picker-input.js @@ -47,7 +47,7 @@ export const AmsDatePickerInput = ({ const isValidOnBlur = () => { return ( inputValue.length > 0 - && !inputValue.match(/^\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}(?::\d{2})? (?:AM|PM)?$/) + && inputValue.match(/^\d{1,2}\/\d{1,2}\/\d{4},? \d{1,2}:\d{2}(?::\d{2})? ?(?:AM|PM)?$/) ); }; From 6fc3f859ce5c001a1a745a26a97fd9d7f7fa0530 Mon Sep 17 00:00:00 2001 From: Lingxi Li Date: Fri, 3 Jun 2022 16:36:30 -0400 Subject: [PATCH 02/14] [Input] Finish basic input integration. --- packages/date-picker/date-picker-input.js | 22 ++++++++++++++++++---- packages/support/date.js | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/date-picker/date-picker-input.js b/packages/date-picker/date-picker-input.js index d8ad358..d29fdfd 100644 --- a/packages/date-picker/date-picker-input.js +++ b/packages/date-picker/date-picker-input.js @@ -3,7 +3,11 @@ import { styled } from '@stitches/react'; import { parseDate } from './processor.js'; import { dateOptions } from '../support/date.js'; -const AmsDatePickerInputContainer = styled('input', {}); +const AmsDatePickerInputContainer = styled('input', { + outline: 'none', + border: 'none', + backgroundColor: 'transparent', +}); export const AmsDatePickerInput = ({ className, @@ -16,13 +20,18 @@ export const AmsDatePickerInput = ({ onKeyPress, onFocus, onBlur, + dateOption = dateOptions, onShouldOpenSelector, onShouldCloseSelector, }) => { - const [inputValue, setInputValue] = useState(value); + const [inputValue, setInputValue] = useState(''); useEffect(() => { - setInputValue(value.toLocaleString('en-US', dateOptions)); + if (value) { + setInputValue(value.toLocaleString('en-US', dateOption)); + } else { + setInputValue(''); + } }, [value]); // This function is a callback when the input is finished by user (on finalizing or on blurring). @@ -34,7 +43,11 @@ export const AmsDatePickerInput = ({ onChange(parsedDate); } } catch (e) { - onError(e); // Return error. + if (onError) { + onError(e); // Return error. + } else { + console.error('ams:', e); // Log error. + } } }; @@ -57,6 +70,7 @@ export const AmsDatePickerInput = ({ className={`ams-date-picker-input ${className ?? ''}`} id={id ?? 'ams-date-picker-input'} css={style} + value={inputValue} onChange={(e) => { setInputValue(e.target.value); }} diff --git a/packages/support/date.js b/packages/support/date.js index 5139543..fa2c49b 100644 --- a/packages/support/date.js +++ b/packages/support/date.js @@ -1,7 +1,7 @@ export const dateOptions = { year: 'numeric', - month: 'numeric', - day: 'numeric', + month: '2-digit', + day: '2-digit', weekday: undefined, hour: 'numeric', minute: 'numeric', From afbc72244d3af3ea19204080874305b932de8523 Mon Sep 17 00:00:00 2001 From: Lingxi Li Date: Fri, 3 Jun 2022 16:36:44 -0400 Subject: [PATCH 03/14] [Headful] Finish the base of headful component and its integration. --- packages/date-picker/date-picker.js | 94 +++++++++++++++++------------ 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/packages/date-picker/date-picker.js b/packages/date-picker/date-picker.js index 05b6248..0807395 100644 --- a/packages/date-picker/date-picker.js +++ b/packages/date-picker/date-picker.js @@ -1,83 +1,101 @@ -import React, { useEffect, useRef, useState } from 'react'; +import React, { useEffect, useState } from 'react'; +import { AmsDatePickerInput } from './date-picker-input'; +import { Layout } from './layout-support.js'; +import { AmsDesign } from '../support/standards.js'; /** * [Ams] (WIP) Magic Date Picker Component. * + * @param {string|undefined} className * @param {string|undefined} id - * @param {string} label * @param {Date|undefined} value * @param {function} onChange - * @param {string|null} hint - * @param {string|null} error * @param {Date|undefined} baseDate + * @param {object} layoutStyle + * @param {object} style + * @param {any} props * @return {JSX.Element} */ export const AmsDatePicker = ({ + className, id = 'ams-date-picker', - label, value, onChange, - hint, - error, baseDate, + layoutStyle, + style, + ...props }) => { // Date picker value state. - const [valueState, setValueState] = useState(null); + const [valueState, setValueState] = useState(value); // Date picker open state. const [isOpen, setIsOpen] = useState(false); - // Date picker hint state. - const [hintState, setHintState] = useState(null); - - // Date picker input field error state. - const [errorState, setErrorState] = useState(null); - - // Date picker anchor element. - const boxRef = useRef(null); - const handlePopoverClose = () => { setIsOpen(false); }; - // Update hint state when hint prop changes. - useEffect(() => { - if (hint) { - setHintState(hint); - } - }, [hint]); - - // Update error state when error prop changes. - useEffect(() => { - if (error) { - setErrorState(error); - } - }, [error]); - // Process the datepicker value into input value. useEffect(() => { if (valueState) { - setHintState(null); - setErrorState(null); if (onChange) { // Call the onChange callback with Date object. // It will always be called nevertheless it is inputted by typing or selecting. onChange(valueState); + } else { + console.warn('ams:', 'onChange callback is not defined.'); + console.log('ams:', 'valueState:', valueState); } } }, [valueState]); return ( -
- {/* TODO */} -
+ {/* TODO: Replenish necessary APIs */} + { + setValueState(value); + }} + style={{ + width: '100%', + height: '100%', + padding: '10px 14px', + fontSize: '$lg', + fontWeight: '400', + ...style, + }} + {...props} + /> + ); }; From 6bd578a8f085f0a675abe77ff96f2a7b2aed6438 Mon Sep 17 00:00:00 2001 From: Lingxi Li Date: Fri, 3 Jun 2022 16:37:01 -0400 Subject: [PATCH 04/14] [UserManual] Optimize the default icon. --- packages/user-manual/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/user-manual/index.js b/packages/user-manual/index.js index 4b55278..87eb7a4 100644 --- a/packages/user-manual/index.js +++ b/packages/user-manual/index.js @@ -1,7 +1,7 @@ import React from 'react'; import { styled } from '@stitches/react'; import * as Dialog from '@radix-ui/react-dialog'; -import { IconQuestionMark } from '@tabler/icons'; +import { IconHelp, IconQuestionMark } from '@tabler/icons'; import { AmsDesign } from '../support/standards.js'; @@ -71,7 +71,9 @@ export const AmsUserManual = ({ style, children }) => { css={style} > {children ?? ( - + )} From 069c42478c1a08b387091696dd68bd7dbdc8f87e Mon Sep 17 00:00:00 2001 From: Lingxi Li Date: Fri, 3 Jun 2022 16:37:14 -0400 Subject: [PATCH 05/14] [General] Fix global css font family issue. --- styles/globals.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles/globals.css b/styles/globals.css index b5e1b2d..095926d 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -26,7 +26,7 @@ a:hover { text-decoration: none; } -button { +* { font-family: 'Inter', -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Helvetica Neue, sans-serif; } From 7206586ec49f347fdb8179fab6c40709dd06712a Mon Sep 17 00:00:00 2001 From: Lingxi Li Date: Fri, 3 Jun 2022 16:37:47 -0400 Subject: [PATCH 06/14] [Website] Update demo. --- pages/_document.js | 5 ++-- pages/index.js | 60 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/pages/_document.js b/pages/_document.js index 53b6ab8..b96800f 100644 --- a/pages/_document.js +++ b/pages/_document.js @@ -3,11 +3,10 @@ import { Html, Head, Main, NextScript } from 'next/document'; import { getCssText } from '../packages/support/stitches.config'; const AmsExampleDocument = () => { - const styles = getCssText(); return ( -