From bce9731477ec37924c309ab0097457aa22432fe2 Mon Sep 17 00:00:00 2001 From: Mihail Novikov Date: Mon, 13 May 2019 23:25:17 +0300 Subject: [PATCH 01/12] Add FileInput buttonText prop --- .../src/components/forms/_file-input.scss | 2 +- .../core/src/components/forms/fileInput.tsx | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/core/src/components/forms/_file-input.scss b/packages/core/src/components/forms/_file-input.scss index 69a677e1a6..748f555015 100644 --- a/packages/core/src/components/forms/_file-input.scss +++ b/packages/core/src/components/forms/_file-input.scss @@ -102,7 +102,7 @@ $file-input-button-padding-large: ($pt-input-height-large - $pt-button-height) / width: $file-input-button-width; text-align: center; line-height: $pt-button-height-small; - content: "Browse"; + content: attr(button-text); } &:hover::after { diff --git a/packages/core/src/components/forms/fileInput.tsx b/packages/core/src/components/forms/fileInput.tsx index 041e0e3111..3ce210fce9 100644 --- a/packages/core/src/components/forms/fileInput.tsx +++ b/packages/core/src/components/forms/fileInput.tsx @@ -68,6 +68,12 @@ export interface IFileInputProps extends React.LabelHTMLAttributes { public static displayName = `${DISPLAYNAME_PREFIX}.FileInput`; public static defaultProps: IFileInputProps = { + buttonText: "Browse", hasSelection: false, inputProps: {}, text: "Choose file...", }; + private input: HTMLSpanElement | null = null; + + public componentDidMount() { + this.changeButtonText(this.props.buttonText); + } + + public componentWillReceiveProps(newProps: IFileInputProps) { + if (this.props.buttonText !== newProps.buttonText) { + this.changeButtonText(newProps.buttonText); + } + } + public render() { const { + buttonText, className, disabled, fill, @@ -108,11 +128,25 @@ export class FileInput extends React.PureComponent { return ( ); } + private createRef = (input: HTMLSpanElement | null) => { + if (input !== null) { + this.input = input; + } + }; + + private changeButtonText = (text: string) => { + if (this.input) { + this.input.setAttribute("button-text", text); + } + }; + private handleInputChange = (e: React.FormEvent) => { Utils.safeInvoke(this.props.onInputChange, e); Utils.safeInvoke(this.props.inputProps.onChange, e); From 7c7c3b5230db47b3baa8f3afb5ac4f8efd8416bf Mon Sep 17 00:00:00 2001 From: Mihail Novikov Date: Mon, 13 May 2019 23:25:45 +0300 Subject: [PATCH 02/12] Change FileInput docs --- .../src/components/forms/_file-input.scss | 5 ++ .../core/src/components/forms/file-input.md | 3 + .../core-examples/fileInputExample.tsx | 66 +++++++++++++++++++ .../src/examples/core-examples/index.ts | 1 + 4 files changed, 75 insertions(+) create mode 100644 packages/docs-app/src/examples/core-examples/fileInputExample.tsx diff --git a/packages/core/src/components/forms/_file-input.scss b/packages/core/src/components/forms/_file-input.scss index 748f555015..a842fd1d07 100644 --- a/packages/core/src/components/forms/_file-input.scss +++ b/packages/core/src/components/forms/_file-input.scss @@ -143,6 +143,11 @@ $file-input-button-padding-large: ($pt-input-height-large - $pt-button-height) / } } +#blueprint-documentation [data-example-id="file-input"] .#{$ns}-file-upload-input::after { + content: "Browse"; +} + + // hack to force the button shadow to display since // it doesn't render correct via the `pt-button` mixin // stylelint-disable-next-line diff --git a/packages/core/src/components/forms/file-input.md b/packages/core/src/components/forms/file-input.md index 46060095e6..85ec4397e3 100644 --- a/packages/core/src/components/forms/file-input.md +++ b/packages/core/src/components/forms/file-input.md @@ -3,6 +3,9 @@ Use the standard `input type="file"` along with a `span` with class `@ns-file-upload-input`. Wrap that all in a `label` with class `@ns-file-input`. + +@reactExample FileInputExample + @## Props This component is a lightweight wrapper around the underlying `