diff --git a/src/components/parts/CheckBox.tsx b/src/components/parts/CheckBox.tsx index 828e6fb..1d08dd2 100644 --- a/src/components/parts/CheckBox.tsx +++ b/src/components/parts/CheckBox.tsx @@ -16,7 +16,7 @@ export const CheckBox = ({ value?: string; id?: string; checked?: boolean; - onChange?: React.ChangeEventHandler; + onChange?: React.ChangeEventHandler; }): JSX.Element => ( diff --git a/src/pages/practice/index.tsx b/src/pages/practice/index.tsx index 6f9a82d..b1ba999 100644 --- a/src/pages/practice/index.tsx +++ b/src/pages/practice/index.tsx @@ -23,12 +23,10 @@ import { MdDelete, MdEdit, MdRemove, + MdHelp, } from 'react-icons/md'; import { BadVisual } from '../../components/examples/link'; -import { - ExampleContainer, - FieldWithBadErrorMessage, -} from '../../components/examples'; +import { ExampleContainer } from '../../components/examples'; import { styled } from 'styled-components'; const SmallButton = styled.button` @@ -62,6 +60,51 @@ const GrayText = styled.p` color: #999; `; +const ErrorMessage = styled(P)` + color: #dc1e32; +`; + +const HelpIcon = styled.span` + color: #8c8989; + font-size: 1.5em; + margin-left: 0.25em; + cursor: pointer; + position: relative; + display: inline-block; +`; +const Help = styled.span` + display: none; + position: absolute; + bottom: calc(100% + 0.5rem); + color: #323232; + left: -1.25rem; + background-color: #fff; + border: 1px solid #d7d2d2; + padding: 0.5em; + border-radius: 0.25em; + box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.3); + z-index: 1; + width: 20rem; + font-size: 0.75rem; + font-weight: normal; + &:before { + content: ''; + position: absolute; + top: 100%; + left: calc(1.5rem - 2px); + border: calc(0.5em + 2px) solid transparent; + border-top-color: #d7d2d2; + } + &:after { + content: ''; + position: absolute; + top: 100%; + left: 1.5rem; + border: 0.5em solid transparent; + border-top-color: #fff; + } +`; + const Practice = (): JSX.Element => { React.useEffect(() => { const html = document.getElementsByTagName('html')[0]; @@ -87,6 +130,11 @@ const Practice = (): JSX.Element => { | 'overseas' >(); const [counter, setCounter] = React.useState(12345); + const [postalCode, setPostalCode] = React.useState(''); + const postalCodeTouchedRef = React.useRef(false); + const [postalCodeMessage, setPostalCodeMessage] = React.useState(''); + const [helpHover, setHelpHover] = React.useState(false); + const [agree, setAgree] = React.useState(false); return ( <> @@ -164,7 +212,24 @@ const Practice = (): JSX.Element => { as="span" /> -

カウンター

+

+ カウンター + + setHelpHover(true)} + onMouseLeave={() => setHelpHover(false)} + onFocus={() => setHelpHover(true)} + onBlur={() => setHelpHover(false)} + tabIndex={0} + /> + + カウンターの値を増減するボタンです。ボタンを押すとカウンターの値が増減します。 + 詳しくは こちら + + +

setCounter(counter + 1)} @@ -381,25 +446,95 @@ const Practice = (): JSX.Element => { - - 利用規約に同意する - + + { + postalCodeTouchedRef.current = true; + setPostalCodeMessage( + postalCodeTouchedRef.current && + !postalCode.match(/^[0-9]{3}-[0-9]{4}$/) + ? '入力形式が正しくありません' + : '' + ); + }} + onChange={(e) => { + const value = e.target.value; + setPostalCode(value); + setPostalCodeMessage( + postalCodeTouchedRef.current && + !value.match(/^[0-9]{3}-[0-9]{4}$/) + ? '入力形式が正しくありません' + : '' + ); + }} + placeholder="141-0032" + aria-label="postal_code" + id="postal_code" + /> + {postalCodeMessage && ( + {postalCodeMessage} + )} - - - - -
- -
+ + + + + + + + + + + + + + + + +
+ setAgree(e.target.checked)} + > + 利用規約に同意する + +
+
+ ); };