From 95746a843b979f83aee5f42fc59f9ddad4ebd305 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 6 Sep 2020 14:20:45 +0300 Subject: [PATCH] Update snippet formatting --- snippets/AutoLink.md | 4 ++-- snippets/ControlledInput.md | 8 ++++---- snippets/CountDown.md | 11 ++++++----- snippets/DataList.md | 4 ++-- snippets/DataTable.md | 4 ++-- snippets/LimitedTextarea.md | 4 ++-- snippets/LimitedWordTextarea.md | 4 ++-- snippets/Loader.md | 4 ++-- snippets/MappedTable.md | 8 ++++---- snippets/Modal.md | 21 ++++++++++----------- snippets/MultiselectCheckbox.md | 6 +++--- snippets/PasswordRevealer.md | 4 ++-- snippets/RippleButton.md | 6 +++--- snippets/Select.md | 17 +++-------------- snippets/Slider.md | 4 ++-- snippets/TextArea.md | 6 +++--- snippets/TreeView.md | 10 +++++----- snippets/UncontrolledInput.md | 6 +++--- 18 files changed, 60 insertions(+), 71 deletions(-) diff --git a/snippets/AutoLink.md b/snippets/AutoLink.md index 70f077b93..a7785c6b3 100644 --- a/snippets/AutoLink.md +++ b/snippets/AutoLink.md @@ -9,7 +9,7 @@ Renders a string as plaintext, with URLs converted to appropriate `` elements - Return a `` with matched URLs rendered as `` elements, dealing with missing protocol prefixes if necessary, and the rest of the string rendered as plaintext. ```jsx -function AutoLink({ text }) { +const AutoLink = ({ text }) => { const delimiter = /((?:https?:\/\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\-]{1,61}[a-z0-9])?\.[^\.|\s])+[a-z\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_\/~#&=;%+?\-\\(\\)]*)/gi; return ( @@ -24,7 +24,7 @@ function AutoLink({ text }) { })} ); -} +}; ``` ```jsx diff --git a/snippets/ControlledInput.md b/snippets/ControlledInput.md index 46a5562f8..dcf1488d4 100644 --- a/snippets/ControlledInput.md +++ b/snippets/ControlledInput.md @@ -6,19 +6,19 @@ tags: components,state,effect,intermediate Renders an `` element with internal state, that uses a callback function to pass its value to the parent component. - Use object destructuring to set defaults for certain attributes of the `` element. -- Use the `React.setState()` hook to create the `value` state variable and give it a value of equal to the `defaultValue` prop. +- Use the `React.useState()` hook to create the `value` state variable and give it a value of equal to the `defaultValue` prop. - Use the `React.useEffect()` hook with a second parameter set to the `value` state variable to call the `callback` function every time `value` is updated. - Render an `` element with the appropriate attributes and use the the `onChange` event to upda the `value` state variable. ```jsx -function ControlledInput({ +const ControlledInput = ({ callback, type = 'text', disabled = false, readOnly = false, defaultValue, placeholder = '' -}) { +}) => { const [value, setValue] = React.useState(defaultValue); React.useEffect(() => { @@ -35,7 +35,7 @@ function ControlledInput({ onChange={({ target: { value } }) => setValue(value)} /> ); -} +}; ``` ```jsx diff --git a/snippets/CountDown.md b/snippets/CountDown.md index e8a517d6d..f7fce6729 100644 --- a/snippets/CountDown.md +++ b/snippets/CountDown.md @@ -15,7 +15,7 @@ Renders a countdown timer that prints a message when it reaches zero. - If `over` is `true`, the timer will display a message instead of the value of `time`. ```jsx -function CountDown({ hours = 0, minutes = 0, seconds = 0 }) { +const CountDown = ({ hours = 0, minutes = 0, seconds = 0 }) => { const [paused, setPaused] = React.useState(false); const [over, setOver] = React.useState(false); const [time, setTime] = React.useState({ @@ -27,24 +27,25 @@ function CountDown({ hours = 0, minutes = 0, seconds = 0 }) { const tick = () => { if (paused || over) return; if (time.hours == 0 && time.minutes == 0 && time.seconds == 0) setOver(true); - else if (time.minutes == 0 && time.seconds == 0) + else if (time.minutes == 0 && time.seconds == 0) { setTime({ hours: time.hours - 1, minutes: 59, seconds: 59 }); - else if (time.seconds == 0) + } else if (time.seconds == 0) { setTime({ hours: time.hours, minutes: time.minutes - 1, seconds: 59 }); - else + } else { setTime({ hours: time.hours, minutes: time.minutes, seconds: time.seconds - 1 }); + } }; const reset = () => { @@ -72,7 +73,7 @@ function CountDown({ hours = 0, minutes = 0, seconds = 0 }) { ); -} +}; ``` ```jsx diff --git a/snippets/DataList.md b/snippets/DataList.md index 61efad250..e3058a4ce 100644 --- a/snippets/DataList.md +++ b/snippets/DataList.md @@ -10,10 +10,10 @@ Renders a list of elements from an array of primitives. - Omit the `isOrdered` prop to render a `