Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [M3-6788] - MUI v5 Migration - Components > TextField #9314

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CopyTooltip } from 'src/components/CopyTooltip/CopyTooltip';
import DownloadTooltip from 'src/components/DownloadTooltip';
import { makeStyles } from '@mui/styles';
import { Theme } from '@mui/material/styles';
import TextField, { Props as TextFieldProps } from 'src/components/TextField';
import { TextField, TextFieldProps } from 'src/components/TextField';

const useStyles = makeStyles((theme: Theme) => ({
removeDisabledStyles: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { CopyTooltip } from 'src/components/CopyTooltip/CopyTooltip';
import { styled } from '@mui/material/styles';
import TextField, { Props as TextFieldProps } from 'src/components/TextField';
import { TextField, TextFieldProps } from 'src/components/TextField';

type CopyableTextFieldProps = TextFieldProps & {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import { CircleProgress } from 'src/components/CircleProgress';
import InputAdornment from 'src/components/core/InputAdornment';
import { styled } from '@mui/material/styles';
import TextField, { Props as TextFieldProps } from 'src/components/TextField';
import { TextField, TextFieldProps } from 'src/components/TextField';

import usePrevious from 'src/hooks/usePrevious';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import Button from 'src/components/Button';
import Typography from 'src/components/core/Typography';
import ActionsPanel from '../ActionsPanel';
import TextField from '../TextField';
import { TextField } from '../TextField';
import Drawer from './Drawer';
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import Button from 'src/components/Button';
import ClickAwayListener from 'src/components/core/ClickAwayListener';
import { makeStyles } from '@mui/styles';
import { Theme } from '@mui/material/styles';
import { TextFieldProps } from 'src/components/core/TextField';
import Typography from 'src/components/core/Typography';
import TextField from 'src/components/TextField';
import { TextField, TextFieldProps } from 'src/components/TextField';

const useStyles = makeStyles((theme: Theme) => ({
'@keyframes fadeIn': {
Expand Down Expand Up @@ -139,7 +138,7 @@ interface Props {
loading: boolean;
}

type PassThroughProps = Props & TextFieldProps;
type PassThroughProps = Props & Omit<TextFieldProps, 'label'>;

type FinalProps = PassThroughProps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { Link } from 'react-router-dom';
import Button from 'src/components/Button';
import { H1Header } from 'src/components/H1Header/H1Header';
import ClickAwayListener from 'src/components/core/ClickAwayListener';
import { TextFieldProps } from 'src/components/core/TextField';
import { fadeIn } from 'src/styles/keyframes';
import { makeStyles } from 'tss-react/mui';
import TextField from '../TextField';
import { TextField, TextFieldProps } from '../TextField';

const useStyles = makeStyles<void, 'editIcon' | 'icon'>()(
(theme: Theme, _params, classes) => ({
Expand Down Expand Up @@ -111,7 +110,7 @@ interface Props {
className?: string;
}

type PassThroughProps = Props & TextFieldProps;
type PassThroughProps = Props & Omit<TextFieldProps, 'label'>;

export const EditableText = (props: PassThroughProps) => {
const { classes } = useStyles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Minus from 'src/assets/icons/LKEminusSign.svg';
import Plus from 'src/assets/icons/LKEplusSign.svg';
import Button from 'src/components/Button';
import { styled } from '@mui/material/styles';
import TextField from 'src/components/TextField';
import { TextField } from 'src/components/TextField';
import Box from '@mui/material/Box';

const sxTextFieldBase = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ReactSelect, {
import CreatableSelect, {
CreatableProps as CreatableSelectProps,
} from 'react-select/creatable';
import { Props as TextFieldProps } from 'src/components/TextField';
import { TextFieldProps } from 'src/components/TextField';
import { convertToKebabCase } from 'src/utilities/convertToKebobCase';
import { reactSelectStyles, useStyles } from './Select.styles';
import { DropdownIndicator } from './components/DropdownIndicator';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { ControlProps } from 'react-select';

import TextField from 'src/components/TextField';
import { TextField } from 'src/components/TextField';

interface Props extends ControlProps<any, any> {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Paper from 'src/components/core/Paper';
import TextField, { Props as TextFieldProps } from 'src/components/TextField';
import { TextField, TextFieldProps } from 'src/components/TextField';
import { Notice } from 'src/components/Notice/Notice';
import { TagsInput, TagsInputProps } from 'src/components/TagsInput/TagsInput';
import { useTheme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { useAllLinodesQuery } from 'src/queries/linodes/linodes';
import Autocomplete from '@mui/material/Autocomplete';
import Popper from '@mui/material/Popper';
import TextField from 'src/components/TextField';
import { TextField } from 'src/components/TextField';

export interface Props {
allowedRegions?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Typography from 'src/components/core/Typography';
import Grid from '@mui/material/Unstable_Grid2';
import { TooltipIcon } from 'src/components/TooltipIcon/TooltipIcon';
import { Notice } from 'src/components/Notice/Notice';
import TextField from 'src/components/TextField';
import { TextField } from 'src/components/TextField';
import { ExtendedIP } from 'src/utilities/ipUtils';

const useStyles = makeStyles()((theme: Theme) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
import TextField from '../TextField';
import { Props as TextFieldProps } from 'src/components/TextField';
import { TextField, TextFieldProps } from '../TextField';

export const HideShowText = (props: TextFieldProps) => {
const [hidden, setHidden] = React.useState(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import Grid from '@mui/material/Unstable_Grid2';
import zxcvbn from 'zxcvbn';
import { StrengthIndicator } from '../PasswordInput/StrengthIndicator';
import { Props as TextFieldProps } from 'src/components/TextField';
import { TextFieldProps } from 'src/components/TextField';
import { HideShowText } from './HideShowText';

interface Props extends TextFieldProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import Box from 'src/components/core/Box';
import { Notice } from 'src/components/Notice/Notice';
import TextField, { Props as TextFieldProps } from 'src/components/TextField';
import { TextField, TextFieldProps } from 'src/components/TextField';
import { getAPIErrorOrDefault, getErrorMap } from 'src/utilities/errorUtils';

interface Props extends TextFieldProps {
Expand Down
62 changes: 62 additions & 0 deletions packages/manager/src/components/TextField.mdx
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Canvas, Meta, Story, Controls } from '@storybook/addon-docs';
import * as TextFieldStories from './TextField.stories';

<Meta of={TextFieldStories} />

# Text Field

<Canvas of={TextFieldStories.Default} />

### Overview

Text fields allow users to enter text into a UI.

### Usage

- Input fields should be sized to the data being entered (ex. the entry for a street address should be wider than a zip code).
- Ensure that the field can accommodate at least one more character than the maximum number to be entered.

### Rules

- Every input must have a descriptive label of what that field is.
- Required fields should include the text “(Required)” as part of the input label.
- If most fields are required, then indicate the optional fields with the text “(Optional)” instead.
- Avoid long labels; use succinct, short and descriptive labels (a word or two) so users can quickly scan your form. <br/> Label text shouldn’t take up multiple lines.
- Placeholder text is the text that users see before they interact with a field. It should be a useful guide to the input type and format <br/> Don’t make the user guess what format they should use for the field. Tell this information up front.

### Best Practices

- A single column form with input fields stacked sequentially is the easiest to understand and leads to the highest success rate. Input fields in multiple columns can be overlooked or add unnecessary visual clutter.
- Grouping related inputs (ex. mailing address) under a subhead or rule can add meaning and make the form feel more manageable.
- Avoid breaking a single form into multiple “papers” unless those sections are truly independent of each other.
- Consider sizing the input field to the data being entered (ex. the field for a street address should be wider than the field for a zip code). Balance this goal with the visual benefits of fields of the same length. A somewhat outsized input that aligns with the fields above and below it might be the best choice.

## Error

### Overview

Error messages are an indicator of system status: they let users know that a hurdle was encountered and give solutions to fix it. Users should not have to memorize instructions in order to fix the error.

### Main Principles

- Should be easy to notice and understand.
- Should give solutions to how to fix the error.
- Users should not have to memorize instructions in order to fix the error.
- Long error messages for short text fields can extend beyond the text field.
- When the user has finished filling in a field and clicks the submit button, an indicator should appear if the field contains an error. Use red to differentiate error fields from normal ones.

<Canvas of={TextFieldStories.Error} />

## Number

### Overview

Number Text Fields are used for strictly numerical input

<Canvas of={TextFieldStories.Number} />

## Component API

<Canvas of={TextFieldStories.Default} />

<Controls />
Loading