Skip to content

Commit

Permalink
More EuiFilePicker styles (elastic#2145)
Browse files Browse the repository at this point in the history
* Added `fullWidth` and `isInvalid` props to EuiFilePicker

* Added a ‘large’ vs 'default' version

* Setting the height statically so that it doesn't shift it's surrounding contents around

* Remove z-indexes: Clashed with any popovers and wasn’t necessary since dom order signifies this

* Added isLoading state (overrides clear button)
  • Loading branch information
cchaos authored Jul 24, 2019
1 parent f33c710 commit 88106c0
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 150 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `partial` glyph to `EuiIcon` ([#2152](https://github.com/elastic/eui/pull/2152))
- Added `tall`, `fullWidth`, and `isInvalid` props to `EuiFilePicker` ([#2145](https://github.com/elastic/eui/pull/2145))

**Bug fixes**

- Fixed invalid `aria-desribedby` values set by `EuiToolTip` ([#2156](https://github.com/elastic/eui/pull/2156))
- Added `"center"` as an acceptable value to `EuiBasicTable`'s `align` proptype ([#2158](https://github.com/elastic/eui/pull/2158))
- Fixed `.eui-textBreakWord` utility class to be cross-browser compatible ([#2157](https://github.com/elastic/eui/pull/2157))
- Fixed truncation and z-index of `EuiFilePicker` ([#2145](https://github.com/elastic/eui/pull/2145))

## [`13.0.0`](https://github.com/elastic/eui/tree/v13.0.0)

Expand Down
12 changes: 10 additions & 2 deletions src-docs/src/views/form_controls/file_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ export class FilePicker extends Component {
<EuiSpacer size="m" />

<EuiFilePicker
id="asdf2"
multiple
display="default"
initialPromptText="Select some files"
onChange={files => {
this.onChange(files);
}}
/>

<EuiSpacer size="m" />

<EuiFilePicker
compressed
initialPromptText="Select some files"
onChange={files => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`EuiFilePicker is rendered 1`] = `
<div
class="euiFilePicker testClass1 testClass2"
class="euiFilePicker euiFilePicker--large testClass1 testClass2"
>
<div
class="euiFilePicker__wrap"
Expand Down
282 changes: 153 additions & 129 deletions src/components/form/file_picker/_file_picker.scss
Original file line number Diff line number Diff line change
@@ -1,175 +1,199 @@
@import '../form_control_layout/mixins';

/**
* REMEMBER: --large modifiers must come last to override --compressed
*/

.euiFilePicker {
.euiFilePicker__wrap {
// Auto means the height isn't set to a fixed size
@include euiFormControlSize(auto);
@include euiFormControlSize;
position: relative;

position: relative;
display: inline-block;
&.euiFilePicker--fullWidth {
max-width: 100%;
}

@at-root {
.euiFilePicker--compressed#{&} {
height: $euiSizeXL;
}
}
&.euiFilePicker--large {
height: auto;
}
}

// The input is an invisiable dropzone / button
.euiFilePicker__input {
position: absolute;
z-index: 0;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
overflow: hidden;
// The input is an invisiable dropzone / button
.euiFilePicker__input {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
overflow: hidden;

&:hover {
cursor: pointer;
}

&:hover {
cursor: pointer;
}
&:hover:disabled {
cursor: not-allowed;
}

&:hover:disabled {
cursor: not-allowed;
}
&:disabled ~ .euiFilePicker__prompt {
color: $euiColorMediumShade;
}
}

&:disabled ~ .euiFilePicker__prompt {
color: $euiColorMediumShade;
}
.euiFilePicker__icon {
position: absolute;
left: $euiSizeM;
top: $euiSizeM;
transition: transform $euiAnimSpeedFast $euiAnimSlightResistance;

.euiFilePicker--compressed & {
top: $euiSizeS;
}

.euiFilePicker__icon {
.euiFilePicker--large & {
position: static;
margin-bottom: $euiSize;
transition: transform $euiAnimSpeedFast $euiAnimSlightResistance;

@at-root {
.euiFilePicker--compressed#{&} {
// sass-lint:disable-block no-important
position: absolute;
top: $euiSizeS;
left: $euiSizeM;
transform: scale(1) !important; // don't scale icon on hover
}
}
}
}

/**
* 1. Don't block the user from dropping files onto the filepicker.
* 2. Put prompt on top of input, so the clear button can intercept the click.
* 3. Ensure space for import icon and clear button (only if it has files)
* 4. Delay focus gradient or else it will only partially transition while file chooser opens
*/
.euiFilePicker__prompt {
@include euiFormControlDefaultShadow;

pointer-events: none; /* 1 */
position: relative; /* 2 */
z-index: 1; /* 2 */
display: block;
padding: $euiSizeL;
text-align: center;

// sass-lint:disable-block indentation
transition:
box-shadow $euiAnimSpeedFast ease-in,
background-color $euiAnimSpeedFast ease-in,
background-image $euiAnimSpeedFast ease-in,
background-size $euiAnimSpeedFast ease-in $euiAnimSpeedFast; /* 4 */

// sass-lint:disable-block mixins-before-declarations
@at-root {
.euiFilePicker--compressed#{&} {
height: $euiFormControlCompressedHeight;
padding: $euiFormControlCompressedPadding;
@include euiFormControlWithIcon; /* 3 */
text-align: left;
}
}
/**
* 1. Don't block the user from dropping files onto the filepicker.
* 3. Ensure space for import icon, loading spinner, and clear button (only if it has files)
* 4. Delay focus gradient or else it will only partially transition while file chooser opens
* 5. Static height so that it doesn't shift it's surrounding contents around
*/
.euiFilePicker__prompt {
@include euiFormControlDefaultShadow;
@include euiFormControlWithIcon; /* 3 */
height: $euiFormControlHeight;
padding-top: $euiFormControlPadding;
padding-right: $euiFormControlPadding;
padding-bottom: $euiFormControlPadding;
pointer-events: none; /* 1 */

// sass-lint:disable-block indentation
transition:
box-shadow $euiAnimSpeedFast ease-in,
background-color $euiAnimSpeedFast ease-in,
background-image $euiAnimSpeedFast ease-in,
background-size $euiAnimSpeedFast ease-in $euiAnimSpeedFast; /* 4 */

.euiFilePicker--compressed & {
height: $euiFormControlCompressedHeight;
padding-top: $euiFormControlCompressedPadding;
padding-right: $euiFormControlCompressedPadding;
padding-bottom: $euiFormControlCompressedPadding;
}

.euiFilePicker__promptText {
@include euiFontSizeS;
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
.euiFilePicker--large & {
height: $euiFilePickerTallHeight; /* 5 */
padding: 0 $euiSizeL;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

@at-root {
// make compressed prompt look like placeholder
.euiFilePicker--compressed#{&} {
color: $euiColorMediumShade;
line-height: $euiSize;
}
}
.euiFilePicker-isInvalid & {
@include euiFormControlInvalidStyle;
}
}

/**
* 1. Undo the pointer-events: none applied to the enclosing prompt.
*/
.euiFilePicker__clearButton {
pointer-events: auto; /* 1 */
.euiFilePicker__promptText {
@include euiFontSizeS;
@include euiTextTruncate;
line-height: $euiSize;
display: block;

// sass-lint:disable-block mixins-before-declarations
@at-root {
.euiFilePicker--compressed#{&} {
@include euiFormControlLayoutClearIcon('.euiFilePicker__clearIcon');
position: absolute;
top: $euiSizeS;
right: $euiSizeM;
}
}
// make normal sized prompt look like placeholder
.euiFilePicker:not(.euiFilePicker--large):not(.euiFilePicker-hasFiles) & {
color: $euiColorMediumShade;
}
}

// Hover and focus
.euiFilePicker__input:hover:not(:disabled) + .euiFilePicker__prompt,
.euiFilePicker__input:focus + .euiFilePicker__prompt {
.euiFilePicker__promptText {
// Adding the underline to the prompt text ensures the underline
// color is the same as the current text color
text-decoration: underline;
}
.euiFilePicker__clearButton,
.euiFilePicker__loadingSpinner {
position: absolute;
right: $euiSizeM;
top: $euiSizeM;

.euiFilePicker__icon {
transform: scale(1.1);
}
.euiFilePicker--compressed & {
top: $euiSizeS;
}
}

// Focus
.euiFilePicker__input:focus + .euiFilePicker__prompt {
@include euiFormControlFocusStyle;
/**
* 1. Undo the pointer-events: none applied to the enclosing prompt.
*/
.euiFilePicker__clearButton {
pointer-events: auto; /* 1 */

.euiFilePicker:not(.euiFilePicker--large) & {
@include euiFormControlLayoutClearIcon('.euiFilePicker__clearIcon');
}

// Disabled
.euiFilePicker__input:disabled + .euiFilePicker__prompt {
@include euiFormControlDisabledStyle;
.euiFilePicker--large & {
position: relative;
top: 0;
right: 0;
}
}

// Focus
.euiFilePicker__showDrop .euiFilePicker__prompt,
.euiFilePicker__input:focus + .euiFilePicker__prompt {
@include euiFormControlFocusStyle;
}

// Disabled
.euiFilePicker__input:disabled + .euiFilePicker__prompt {
@include euiFormControlDisabledStyle;
}

&.euiFilePicker-hasFiles.euiFilePicker--compressed .euiFilePicker__prompt {
// Make space for the icons on the right
.euiFilePicker:not(.euiFilePicker--large) {
&.euiFilePicker-isLoading .euiFilePicker__prompt,
&.euiFilePicker-hasFiles .euiFilePicker__prompt {
@include euiFormControlWithIcon(false, 'right'); /* 3 */
}
}

// When the filepicker has files in it, but not in compressed mode
&:not(.euiFilePicker--compressed).euiFilePicker-hasFiles .euiFilePicker__promptText {
font-weight: $euiFontWeightBold;
}
// When the filepicker has files in it
.euiFilePicker-hasFiles .euiFilePicker__promptText {
color: $euiTextColor;
}

// Large styles only
.euiFilePicker--large {
// sass-lint:disable-block nesting-depth
// Hover and focus
.euiFilePicker__input:hover:not(:disabled),
.euiFilePicker__input:focus {
+ .euiFilePicker__prompt {
.euiFilePicker__promptText {
// Adding the underline to the prompt text ensures the underline
// color is the same as the current text color
text-decoration: underline;
}

// When the filepicker has files in it, AND in compressed mode
&.euiFilePicker--compressed.euiFilePicker-hasFiles .euiFilePicker__promptText {
color: $euiTextColor;
.euiFilePicker__icon {
transform: scale(1.1);
}
}
}

// When you are dragging files over the dropzone
// While dragging files over the dropzone
&.euiFilePicker__showDrop .euiFilePicker__prompt {
@include euiFormControlFocusStyle;

.euiFilePicker__promptText {
text-decoration: underline;
}

.euiFilePicker__icon {
transform: scale(1.1);
color: $euiColorPrimary;
}
}

&.euiFilePicker-hasFiles .euiFilePicker__promptText {
font-weight: $euiFontWeightBold;
}
}
1 change: 1 addition & 0 deletions src/components/form/file_picker/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import 'variables';
@import 'file_picker';
1 change: 1 addition & 0 deletions src/components/form/file_picker/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$euiFilePickerTallHeight: $euiSize * 8;
Loading

0 comments on commit 88106c0

Please sign in to comment.