Skip to content

Commit

Permalink
feat(react): added disabled prop to file uploader (#10613)
Browse files Browse the repository at this point in the history
* feat(react): added disabled prop to file uploader

* test(react): updated FileUploader snapshot

* chore(fileuploader): add disabled prop arg control to v11 storybook

Co-authored-by: Taylor Jones <[email protected]>
Co-authored-by: Lauren Rice <[email protected]>
  • Loading branch information
3 people authored Feb 10, 2022
1 parent dcc8563 commit 7310215
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,7 @@ Map {
"accept": Array [],
"buttonKind": "primary",
"buttonLabel": "",
"disabled": false,
"filenameStatus": "uploading",
"iconDescription": "Provide icon description",
"multiple": false,
Expand Down Expand Up @@ -2619,6 +2620,9 @@ Map {
"className": Object {
"type": "string",
},
"disabled": Object {
"type": "bool",
},
"filenameStatus": Object {
"args": Array [
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const props = {
),
buttonLabel: text('The button label (buttonLabel)', 'Add file'),
buttonKind: buttonKind || 'primary',
disabled: boolean('Disabled (disabled)', false),
size: select('Button size (size)', sizes, 'default'),
filenameStatus: select(
'Status for file name (filenameStatus)',
Expand Down
21 changes: 19 additions & 2 deletions packages/react/src/components/FileUploader/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default class FileUploader extends React.Component {
*/
className: PropTypes.string,

/**
* Specify whether file input is disabled
*/
disabled: PropTypes.bool,

/**
* Specify the status of the File Upload
*/
Expand Down Expand Up @@ -100,6 +105,7 @@ export default class FileUploader extends React.Component {
static contextType = PrefixContext;

static defaultProps = {
disabled: false,
iconDescription: FeatureFlags.enabled('enable-v11-release')
? undefined
: 'Provide icon description',
Expand Down Expand Up @@ -167,6 +173,7 @@ export default class FileUploader extends React.Component {
iconDescription,
buttonLabel,
buttonKind,
disabled,
filenameStatus,
labelDescription,
labelTitle,
Expand All @@ -186,6 +193,11 @@ export default class FileUploader extends React.Component {
[className]: className,
});

const getHelperLabelClasses = (baseClass) =>
classNames(baseClass, {
[`${prefix}--label-description--disabled`]: disabled,
});

const selectedFileClasses = classNames(`${prefix}--file__selected-file`, {
[`${prefix}--file__selected-file--md`]: size === 'field' || size === 'md',
[`${prefix}--file__selected-file--sm`]: size === 'small' || size === 'sm',
Expand All @@ -194,10 +206,15 @@ export default class FileUploader extends React.Component {
return (
<div className={classes} {...other}>
{FeatureFlags.enabled('enable-v11-release') && !labelTitle ? null : (
<p className={`${prefix}--file--label`}>{labelTitle}</p>
<p className={getHelperLabelClasses(`${prefix}--file--label`)}>
{labelTitle}
</p>
)}
<p className={`${prefix}--label-description`}>{labelDescription}</p>
<p className={getHelperLabelClasses(`${prefix}--label-description`)}>
{labelDescription}
</p>
<FileUploaderButton
disabled={disabled}
labelText={buttonLabel}
multiple={multiple}
buttonKind={buttonKind}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ _FileUploader.args = {
accept: ['.jpg', '.png'],
name: '',
multiple: true,
disabled: false,
iconDescription: 'Clear file',
};
_FileUploader.argTypes = {
Expand Down

0 comments on commit 7310215

Please sign in to comment.