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

TextareaControl: Update styles #64586

Merged
merged 9 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -54,4 +54,5 @@ Default.args = {
__nextHasNoMarginBottom: true,
label: 'Text',
help: 'Enter some text',
placeholder: 'Placeholder',
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,95 @@
* External dependencies
*/
import styled from '@emotion/styled';
import { css } from '@emotion/react';

/**
* Internal dependencies
*/
import { inputControl } from '../../utils/input';
import { font } from '../../utils/font';
import { COLORS } from '../../utils/colors-values';
import { CONFIG } from '../../utils';
import { breakpoint } from '../../utils/breakpoint';

const inputStyleNeutral = css`
box-shadow: 0 0 0 transparent;
border-radius: ${ CONFIG.radiusSmall };
border: ${ CONFIG.borderWidth } solid ${ COLORS.ui.border };

@media not ( prefers-reduced-motion ) {
transition: box-shadow 0.1s linear;
}
`;

const inputStyleFocus = css`
border-color: ${ COLORS.theme.accent };
box-shadow: 0 0 0
calc( ${ CONFIG.borderWidthFocus } - ${ CONFIG.borderWidth } )
${ COLORS.theme.accent };

// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 2px solid transparent;
`;

const deprecatedStyles = ( { __next40pxDefaultSize = false } ) => {
if ( ! __next40pxDefaultSize ) {
return css`
padding: 6px 8px;
`;
}

return css`
// Vertical padding is to match the standard 40px control height when rows=1.
// Subtracts 1px each to account for the border width.
ciampo marked this conversation as resolved.
Show resolved Hide resolved
padding: 9px 11px;
`;
};

export const StyledTextarea = styled.textarea`
width: 100%;
${ inputControl }
display: block;
font-family: ${ font( 'default.fontFamily' ) };
line-height: 20px;
${ deprecatedStyles }
${ inputStyleNeutral };

/* Fonts smaller than 16px causes mobile safari to zoom. */
font-size: ${ font( 'mobileTextMinFontSize' ) };

${ breakpoint( 'small' ) } {
font-size: ${ font( 'default.fontSize' ) };
}

&:focus {
${ inputStyleFocus }
}

// Use opacity to work in various editor styles.
&::-webkit-input-placeholder {
color: ${ COLORS.ui.darkGrayPlaceholder };
}

&::-moz-placeholder {
opacity: 1; // Necessary because Firefox reduces this from 1.
color: ${ COLORS.ui.darkGrayPlaceholder };
}

&:-ms-input-placeholder {
color: ${ COLORS.ui.darkGrayPlaceholder };
}

.is-dark-theme & {
&::-webkit-input-placeholder {
color: ${ COLORS.ui.lightGrayPlaceholder };
}

&::-moz-placeholder {
opacity: 1; // Necessary because Firefox reduces this from 1.
color: ${ COLORS.ui.lightGrayPlaceholder };
}

&:-ms-input-placeholder {
color: ${ COLORS.ui.lightGrayPlaceholder };
}
}
`;
6 changes: 6 additions & 0 deletions packages/components/src/textarea-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export type TextareaControlProps = Pick<
BaseControlProps,
'hideLabelFromVision' | 'help' | 'label' | '__nextHasNoMarginBottom'
> & {
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
/**
* A function that receives the new value of the textarea each time it
* changes.
Expand Down
30 changes: 0 additions & 30 deletions packages/components/src/utils/input/base.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/components/src/utils/input/index.js

This file was deleted.

63 changes: 0 additions & 63 deletions packages/components/src/utils/input/input-control.js

This file was deleted.

Loading