diff --git a/snippets/Loader.md b/snippets/Loader.md index 28423ad04..51613aa61 100644 --- a/snippets/Loader.md +++ b/snippets/Loader.md @@ -3,10 +3,10 @@ title: Loader tags: components,beginner --- -Creates a spinning loader component. +Renders a spinning loader component. -- Define appropriate CSS styles and animations for the component's elements. -- Define the component, which returns a simple SVG, whose size is determined by the `size` prop. +- Render an SVG, whose `height` and `width` are determined by the `size` prop. +- Use CSS to animate the SVG, creating a spinning animation. ```css .loader { diff --git a/snippets/Mailto.md b/snippets/Mailto.md index e776c1bcb..130fb213d 100644 --- a/snippets/Mailto.md +++ b/snippets/Mailto.md @@ -3,16 +3,19 @@ title: Mailto tags: components,beginner --- -Renders a link formatted to send an email. +Renders a link formatted to send an email (`mailto:` link). -- Destructure the component's props, use `email`, `subject` and `body` to create a `` element with an appropriate `href` attribute. +- Use the `email`, `subject` and `body` props to create a `` element with an appropriate `href` attribute. +- Use `encodeURIcomponent` to safely encode the `subject` and `body` into the link URL. - Render the link with `children` as its content. ```jsx -const Mailto = ({ email, subject, body, children }) => { - return ( - {children} - ); +const Mailto = ({ email, subject = '', body = '', children }) => { + let params = subject || body ? '?' : ''; + if (subject) params += `subject=${encodeURIComponent(subject)}`; + if (body) params += `${subject ? '&' : ''}body=${encodeURIComponent(body)}`; + + return {children}; }; ``` diff --git a/snippets/Tooltip.md b/snippets/Tooltip.md index fb3b17966..ef487b878 100644 --- a/snippets/Tooltip.md +++ b/snippets/Tooltip.md @@ -5,26 +5,36 @@ tags: components,state,children,beginner Renders a tooltip component. -- Use the `React.useState()` hook to create the `show` variable and initialize it to `false`. -- Return a `