Skip to content

Commit

Permalink
Merge pull request #1598 from public-convenience-ltd/add-textarea-to-…
Browse files Browse the repository at this point in the history
…design-system

Add textarea to design system
  • Loading branch information
stphnnnn authored Dec 4, 2023
2 parents 8074a19 + 895b835 commit 45bc4dd
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"functional/no-method-signature": 0,
"no-var": "error",
"no-param-reassign": "error",
"prefer-const": "error"
"prefer-const": "error",
"jsx-a11y/label-has-associated-control": [
2,
{ "controlComponents": ["TextArea"] }
]
},
"settings": {
"react": {
Expand Down
17 changes: 4 additions & 13 deletions src/components/EntryForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState, useMemo } from 'react';
import styled from '@emotion/styled';
import {
useForm,
Controller,
Expand Down Expand Up @@ -27,6 +26,7 @@ import crosshair from '../../public/crosshair-small.svg';
import { useMapState } from './MapState';
import Icon from '../design-system/components/Icon';
import { css } from '@emotion/react';
import TextArea from '../design-system/components/TextArea';

type OpeningDayStates =
| `${Lowercase<Weekdays>}-is-open`
Expand All @@ -42,16 +42,6 @@ const openingTimesFields = WEEKDAYS.flatMap((day): OpeningDayStates[] => {
];
});

const Textarea = styled.textarea`
display: block;
height: 10rem;
width: 100%;
margin-top: ${(props) => props.theme.space[1]}px;
padding: ${(props) => props.theme.space[2]}px;
color: ${(props) => props.theme.colors.primary};
border: 1px solid ${(props) => props.theme.colors.primary};
`;

interface Question {
field: string;
subQuestion: string | React.ReactElement;
Expand Down Expand Up @@ -783,10 +773,11 @@ const EntryForm = ({ title, loo, children, ...props }) => {

<Spacer mt={4} />

<label htmlFor="notes">
<label>
7. Notes
<Textarea
<TextArea
name="notes"
rows={6}
defaultValue={loo.notes || ''}
data-testid="notes"
placeholder="Add any other useful information about the toilet here"
Expand Down
7 changes: 7 additions & 0 deletions src/design-system/components/TextArea/TextArea.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.text-area {
display: block;
width: 100%;
padding: var(--space-2xs);
color: var(--color-blue);
border: 1px solid var(--color-blue);
}
14 changes: 14 additions & 0 deletions src/design-system/components/TextArea/TextArea.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta, StoryObj } from '@storybook/react';

import TextArea from './TextArea';

const meta: Meta<typeof TextArea> = {
title: 'Design-System/Form Elements/TextArea',
component: TextArea,
};

export default meta;

export const Primary: StoryObj<typeof TextArea> = {
render: () => <TextArea />,
};
10 changes: 10 additions & 0 deletions src/design-system/components/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ComponentPropsWithoutRef, forwardRef } from 'react';

const TextArea = forwardRef<
HTMLTextAreaElement,
ComponentPropsWithoutRef<'textarea'>
>((props, ref) => <textarea className="text-area" ref={ref} {...props} />);

TextArea.displayName = 'TextArea';

export default TextArea;
1 change: 1 addition & 0 deletions src/design-system/components/TextArea/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './TextArea';
1 change: 1 addition & 0 deletions src/design-system/components/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@import 'src/design-system/components/InputField/InputField.css';
@import 'src/design-system/components/RadioInput/RadioInput.css';
@import 'src/design-system/components/Switch/Switch.css';
@import 'src/design-system/components/TextArea/TextArea.css';
13 changes: 5 additions & 8 deletions src/pages/loos/[id]/remove.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { GetServerSideProps } from 'next';
import NotFound from '../../404.page';
import { css } from '@emotion/react';
import { useMapState } from '../../../components/MapState';
import TextArea from '../../../design-system/components/TextArea';

const RemovePage: PageFindLooByIdComp | React.FC<{ notFound?: boolean }> =
function (props) {
Expand Down Expand Up @@ -58,7 +59,7 @@ const RemovePage: PageFindLooByIdComp | React.FC<{ notFound?: boolean }> =
setMapState({ searchLocation: undefined });
// redirect to updated toilet entry page
router.push(
`/api/loos/${removeData.submitRemovalReport.loo.id}/revalidate?message=removed`
`/api/loos/${removeData.submitRemovalReport.loo.id}/revalidate?message=removed`,
);
}
}, [removeData, router, setMapState]);
Expand Down Expand Up @@ -138,16 +139,12 @@ const RemovePage: PageFindLooByIdComp | React.FC<{ notFound?: boolean }> =
<form onSubmit={onSubmit}>
<label>
<b>Reason for removal</b>
<textarea
type="text"
<TextArea
rows={4}
name="reason"
value={reason}
onChange={updateReason}
required
css={{
height: '100px',
width: '100%',
}}
/>
</label>

Expand Down Expand Up @@ -179,7 +176,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
{
variables: { id: ctx.params.id as string },
},
ctx
ctx,
);

if (res.props.error || !res.props.data) {
Expand Down

1 comment on commit 45bc4dd

@vercel
Copy link

@vercel vercel bot commented on 45bc4dd Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.