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

[Core] File input text styling for active selections #3375

Merged
merged 4 commits into from
Apr 1, 2019
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
1 change: 1 addition & 0 deletions packages/core/src/common/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const RADIO = `${NS}-radio`;
export const SWITCH = `${NS}-switch`;
export const SWITCH_INNER_TEXT = `${SWITCH}-inner-text`;
export const FILE_INPUT = `${NS}-file-input`;
export const FILE_INPUT_HAS_SELECTION = `${NS}-file-input-has-selection`;
export const FILE_UPLOAD_INPUT = `${NS}-file-upload-input`;

export const KEY = `${NS}-key`;
Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/components/forms/_file-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Markup:
:disabled - Disabled
.#{$ns}-large - Larger size
.#{$ns}-fill - Take up full width of parent element
.#{$ns}-file-input-has-selection - User has made a selection

Styleguide file-input
*/
Expand All @@ -39,7 +40,8 @@ $file-input-button-padding-large: ($pt-input-height-large - $pt-button-height) /
// unlike other form controls that directly style native elements,
// pt-file-input wraps and hides the native element for better control over
// visual styles. to disable, we need to disable the hidden child input, not
// the surrounding wrapper. see #689 for gory details.
// the surrounding wrapper. @see https://github.com/palantir/blueprint/issues/689
// for gory details.
&:disabled + .#{$ns}-file-upload-input,
&.#{$ns}-disabled + .#{$ns}-file-upload-input {
@include pt-input-disabled();
Expand All @@ -58,6 +60,16 @@ $file-input-button-padding-large: ($pt-input-height-large - $pt-button-height) /
}
}

&.#{$ns}-file-input-has-selection {
.#{$ns}-file-upload-input {
color: $pt-text-color;
}

.#{$ns}-dark & .#{$ns}-file-upload-input {
color: $pt-dark-text-color;
}
}

&.#{$ns}-fill {
width: 100%;
}
Expand All @@ -76,6 +88,7 @@ $file-input-button-padding-large: ($pt-input-height-large - $pt-button-height) /
right: 0;
left: 0;
padding-right: $file-input-button-width + $input-padding-horizontal;
color: $pt-text-color-disabled;
user-select: none;

&::after {
Expand Down Expand Up @@ -114,7 +127,7 @@ $file-input-button-padding-large: ($pt-input-height-large - $pt-button-height) /

.#{$ns}-dark & {
@include pt-dark-input();
color: $pt-dark-text-color-muted;
color: $pt-dark-text-color-disabled;

&::after {
@include pt-dark-button();
Expand Down
21 changes: 20 additions & 1 deletion packages/core/src/components/forms/fileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export interface IFileInputProps extends React.LabelHTMLAttributes<HTMLLabelElem
*/
fill?: boolean;

/**
* Whether the user has made a selection in the input. This will affect the component's
* text styling. Make sure to set a non-empty value for the text prop as well.
* @default false
*/
hasSelection?: boolean;

/**
* The props to pass to the child input.
* `disabled` will be ignored in favor of the top-level prop.
Expand Down Expand Up @@ -59,16 +66,28 @@ export class FileInput extends React.PureComponent<IFileInputProps, {}> {
public static displayName = `${DISPLAYNAME_PREFIX}.FileInput`;

public static defaultProps: IFileInputProps = {
hasSelection: false,
inputProps: {},
text: "Choose file...",
};

public render() {
const { className, fill, disabled, inputProps, onInputChange, large, text, ...htmlProps } = this.props;
const {
className,
disabled,
fill,
hasSelection,
inputProps,
large,
onInputChange,
text,
...htmlProps
} = this.props;

const rootClasses = classNames(
Classes.FILE_INPUT,
{
[Classes.FILE_INPUT_HAS_SELECTION]: hasSelection,
[Classes.DISABLED]: disabled,
[Classes.FILL]: fill,
[Classes.LARGE]: large,
Expand Down