Skip to content

Commit 627462e

Browse files
committed
Button: update enum to explicit export and in constant case
1 parent 8f0f0b5 commit 627462e

File tree

13 files changed

+69
-52
lines changed

13 files changed

+69
-52
lines changed

client/common/Button.stories.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { action } from '@storybook/addon-actions';
33

4-
import { Button } from './Button';
4+
import { Button, ButtonDisplays, ButtonKinds, ButtonTypes } from './Button';
55
import { GithubIcon, DropdownArrowIcon, PlusIcon } from './icons';
66

77
export default {
@@ -15,13 +15,13 @@ export default {
1515
};
1616

1717
export const AllFeatures = (args) => (
18-
<Button disabled={args.disabled} type="submit" label={args.label}>
18+
<Button disabled={args.disabled} type={ButtonTypes.SUBMIT} label={args.label}>
1919
{args.children}
2020
</Button>
2121
);
2222

2323
export const SubmitButton = () => (
24-
<Button type="submit" label="submit">
24+
<Button type={ButtonTypes.SUBMIT} label="submit">
2525
This is a submit button
2626
</Button>
2727
);
@@ -59,7 +59,7 @@ export const ButtonWithIconAfter = () => (
5959
);
6060

6161
export const InlineButtonWithIconAfter = () => (
62-
<Button iconAfter={<DropdownArrowIcon />} display={Button.displays.inline}>
62+
<Button iconAfter={<DropdownArrowIcon />} display={ButtonDisplays.INLINE}>
6363
File name
6464
</Button>
6565
);
@@ -68,6 +68,6 @@ export const InlineIconOnlyButton = () => (
6868
<Button
6969
aria-label="Add to collection"
7070
iconBefore={<PlusIcon />}
71-
display={Button.displays.inline}
71+
display={ButtonDisplays.INLINE}
7272
/>
7373
);

client/common/Button.tsx

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,36 @@ import styled from 'styled-components';
33
import { Link } from 'react-router-dom';
44
import { remSize, prop } from '../theme';
55

6-
enum Kinds {
7-
primary = 'primary',
8-
secondary = 'secondary'
6+
/**
7+
* Enum for the visual style of a Button.
8+
*
9+
* These values transpile to lowercase strings (`'primary' | 'secondary'`)
10+
* that map directly to keys in the `Button` object in `theme.js` for styling.
11+
*/
12+
export enum ButtonKinds {
13+
PRIMARY = 'primary',
14+
SECONDARY = 'secondary'
915
}
10-
11-
enum Displays {
12-
block = 'block',
13-
inline = 'inline'
16+
/**
17+
* Enum for the display type of a Button.
18+
*
19+
* These values transpile to lowercase strings (`'block' | 'inline'`)
20+
* and map to display styles in the `Button` object in `theme.js`.
21+
*/
22+
export enum ButtonDisplays {
23+
BLOCK = 'block',
24+
INLINE = 'inline'
1425
}
15-
16-
enum ButtonTypes {
17-
button = 'button',
18-
submit = 'submit'
26+
/**
27+
* Enum for the native HTML button type.
28+
*
29+
* These values transpile to lowercase strings (`'button' | 'submit'`)
30+
* and correspond to the `type` attribute on a native <button>.
31+
* They can also be used in `theme.js` if needed for button-specific styles.
32+
*/
33+
export enum ButtonTypes {
34+
BUTTON = 'button',
35+
SUBMIT = 'submit'
1936
}
2037

2138
export interface ButtonProps extends React.HTMLAttributes<HTMLElement> {
@@ -31,7 +48,7 @@ export interface ButtonProps extends React.HTMLAttributes<HTMLElement> {
3148
/**
3249
* The display type of the button—inline or block
3350
*/
34-
display?: Displays;
51+
display?: ButtonDisplays;
3552
/**
3653
* SVG icon to place after child content
3754
*/
@@ -47,7 +64,7 @@ export interface ButtonProps extends React.HTMLAttributes<HTMLElement> {
4764
/**
4865
* The kind of button - determines how it appears visually
4966
*/
50-
kind?: Kinds;
67+
kind?: ButtonKinds;
5168
/**
5269
* Specifying an href will use an <a> to link to the URL
5370
*/
@@ -78,8 +95,8 @@ export interface ButtonProps extends React.HTMLAttributes<HTMLElement> {
7895
}
7996

8097
interface StyledButtonProps extends ButtonProps {
81-
kind: Kinds;
82-
display: Displays;
98+
kind: ButtonKinds;
99+
display: ButtonDisplays;
83100
}
84101

85102
// The '&&&' will increase the specificity of the
@@ -89,7 +106,7 @@ const StyledButton = styled.button<StyledButtonProps>`
89106
&&& {
90107
font-weight: bold;
91108
display: ${({ display }) =>
92-
display === Displays.inline ? 'inline-flex' : 'flex'};
109+
display === ButtonDisplays.INLINE ? 'inline-flex' : 'flex'};
93110
justify-content: center;
94111
align-items: center;
95112
@@ -183,15 +200,15 @@ const StyledInlineButton = styled.button`
183200
*/
184201
export const Button = ({
185202
children = null,
186-
display = Displays.block,
203+
display = ButtonDisplays.BLOCK,
187204
href,
188-
kind = Kinds.primary,
205+
kind = ButtonKinds.PRIMARY,
189206
iconBefore = null,
190207
iconAfter = null,
191208
iconOnly = false,
192209
'aria-label': ariaLabel,
193210
to,
194-
type = ButtonTypes.button,
211+
type = ButtonTypes.BUTTON,
195212
...props
196213
}: ButtonProps) => {
197214
const hasChildren = React.Children.count(children) > 0;
@@ -251,6 +268,3 @@ export const Button = ({
251268
</StyledComponent>
252269
);
253270
};
254-
255-
Button.kinds = Kinds;
256-
Button.displays = Displays;

client/common/IconButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ComponentType } from 'react';
22
import styled from 'styled-components';
3-
import { Button, ButtonProps } from './Button';
3+
import { Button, ButtonProps, ButtonDisplays } from './Button';
44
import { remSize } from '../theme';
55

66
const ButtonWrapper = styled(Button)`
@@ -23,7 +23,7 @@ export const IconButton = ({ icon: Icon, ...otherProps }: IconButtonProps) => (
2323
<ButtonWrapper
2424
iconBefore={Icon ? <Icon /> : undefined}
2525
iconOnly
26-
display={Button.displays.inline}
26+
display={ButtonDisplays.INLINE}
2727
focusable={false}
2828
{...otherProps}
2929
/>

client/modules/IDE/components/NewFileForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useDispatch } from 'react-redux';
55
import { handleCreateFile } from '../actions/files';
66
import { CREATE_FILE_REGEX } from '../../../../server/utils/fileUtils';
77

8-
import { Button } from '../../../common/Button';
8+
import { Button, ButtonTypes } from '../../../common/Button';
99

1010
function NewFileForm() {
1111
const fileNameInput = useRef(null);
@@ -57,7 +57,7 @@ function NewFileForm() {
5757
</Field>
5858
<Field name="submitButton">
5959
{() => (
60-
<Button type="submit" disabled={submitting}>
60+
<Button type={ButtonTypes.SUBMIT} disabled={submitting}>
6161
{t('NewFileForm.AddFileSubmit')}
6262
</Button>
6363
)}

client/modules/IDE/components/NewFolderForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useRef, useEffect } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { Form, Field } from 'react-final-form';
44
import { useDispatch } from 'react-redux';
5-
import { Button } from '../../../common/Button';
5+
import { Button, ButtonTypes } from '../../../common/Button';
66
import { handleCreateFolder } from '../actions/files';
77

88
function NewFolderForm() {
@@ -54,7 +54,7 @@ function NewFolderForm() {
5454
</Field>
5555
<Field name="submitButton">
5656
{() => (
57-
<Button type="submit" disabled={submitting}>
57+
<Button type={ButtonTypes.SUBMIT} disabled={submitting}>
5858
{t('NewFolderForm.AddFolderSubmit')}
5959
</Button>
6060
)}

client/modules/User/components/APIKeyForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
22
import React, { useState } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import { useDispatch, useSelector } from 'react-redux';
5-
import { Button } from '../../../common/Button';
5+
import { Button, ButtonTypes } from '../../../common/Button';
66
import { PlusIcon } from '../../../common/icons';
77
import CopyableInput from '../../IDE/components/CopyableInput';
88
import { createApiKey, removeApiKey } from '../actions';
@@ -78,7 +78,7 @@ const APIKeyForm = () => {
7878
disabled={keyLabel === ''}
7979
iconBefore={<PlusIcon />}
8080
label="Create new key"
81-
type="submit"
81+
type={ButtonTypes.SUBMIT}
8282
>
8383
{t('APIKeyForm.CreateTokenSubmit')}
8484
</Button>

client/modules/User/components/AccountForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Form, Field } from 'react-final-form';
33
import { useSelector, useDispatch } from 'react-redux';
44
import { useTranslation } from 'react-i18next';
5-
import { Button } from '../../../common/Button';
5+
import { Button, ButtonTypes } from '../../../common/Button';
66
import { validateSettings } from '../../../utils/reduxFormUtils';
77
import { updateSettings, initiateVerification } from '../actions';
88
import { apiClient } from '../../../utils/apiClient';
@@ -175,7 +175,7 @@ function AccountForm() {
175175
)}
176176
</Field>
177177
)}
178-
<Button type="submit" disabled={submitting || invalid}>
178+
<Button type={ButtonTypes.SUBMIT} disabled={submitting || invalid}>
179179
{t('AccountForm.SaveAccountDetails')}
180180
</Button>
181181
</form>

client/modules/User/components/CollectionCreate.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
44
import { useDispatch } from 'react-redux';
55

66
import { generateCollectionName } from '../../../utils/generateRandomName';
7-
import { Button } from '../../../common/Button';
7+
import { Button, ButtonTypes } from '../../../common/Button';
88
import { createCollection } from '../../IDE/actions/collections';
99

1010
const CollectionCreate = () => {
@@ -74,7 +74,7 @@ const CollectionCreate = () => {
7474
rows="6"
7575
/>
7676
</p>
77-
<Button type="submit" disabled={invalid}>
77+
<Button type={ButtonTypes.SUBMIT} disabled={invalid}>
7878
{t('CollectionCreate.SubmitCollectionCreate')}
7979
</Button>
8080
</form>

client/modules/User/components/CookieConsent.jsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
1010
import { getConfig } from '../../../utils/getConfig';
1111
import { setUserCookieConsent } from '../actions';
1212
import { remSize, prop, device } from '../../../theme';
13-
import { Button } from '../../../common/Button';
13+
import { Button, ButtonKinds } from '../../../common/Button';
1414

1515
const CookieConsentContainer = styled.div`
1616
position: fixed;
@@ -177,10 +177,7 @@ function CookieConsent({ hide }) {
177177
/>
178178
</CookieConsentCopy>
179179
<CookieConsentButtons>
180-
<Button
181-
kind={Button.kinds.secondary}
182-
onClick={acceptAllCookies}
183-
>
180+
<Button kind={ButtonKinds.SECONDARY} onClick={acceptAllCookies}>
184181
{t('Cookies.AllowAll')}
185182
</Button>
186183
<Button onClick={acceptEssentialCookies}>

client/modules/User/components/LoginForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
33
import { Form, Field } from 'react-final-form';
44
import { useDispatch } from 'react-redux';
55
import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai';
6-
import { Button } from '../../../common/Button';
6+
import { Button, ButtonTypes } from '../../../common/Button';
77
import { validateLogin } from '../../../utils/reduxFormUtils';
88
import { validateAndLoginUser } from '../actions';
99
import { useSyncFormTranslations } from '../../../common/useSyncFormTranslations';
@@ -105,7 +105,7 @@ function LoginForm() {
105105
{t('LoginForm.Errors.invalidCredentials')}
106106
</span>
107107
)}
108-
<Button type="submit" disabled={submitting}>
108+
<Button type={ButtonTypes.SUBMIT} disabled={submitting}>
109109
{t('LoginForm.Submit')}
110110
</Button>
111111
</form>

0 commit comments

Comments
 (0)