Skip to content

Commit 8d80471

Browse files
mirkatyxla
andauthored
FormFileUpload: Deprecate 36px default size (#67438)
* FormFileUpload: Deprecate 36px default size * Add changelog * Tweak descriptions Co-authored-by: mirka <[email protected]> Co-authored-by: tyxla <[email protected]>
1 parent b61f913 commit 8d80471

File tree

7 files changed

+92
-58
lines changed

7 files changed

+92
-58
lines changed

packages/components/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- `CustomSelectControl`: Deprecate 36px default size ([#67441](https://github.com/WordPress/gutenberg/pull/67441)).
1010
- `NumberControl`: Deprecate 36px default size ([#66730](https://github.com/WordPress/gutenberg/pull/66730)).
1111
- `UnitControl`: Deprecate 36px default size ([#66791](https://github.com/WordPress/gutenberg/pull/66791)).
12+
- `FormFileUpload`: Deprecate 36px default size ([#67438](https://github.com/WordPress/gutenberg/pull/67438)).
1213

1314
### Enhancements
1415

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,105 @@
11
# FormFileUpload
22

3-
FormFileUpload is a component that allows users to select files from their local device.
3+
<!-- This file is generated automatically and cannot be edited directly. Make edits via TypeScript types and TSDocs. -->
44

5-
## Usage
5+
<p class="callout callout-info">See the <a href="https://wordpress.github.io/gutenberg/?path=/docs/components-formfileupload--docs">WordPress Storybook</a> for more detailed, interactive documentation.</p>
6+
7+
FormFileUpload allows users to select files from their local device.
68

79
```jsx
810
import { FormFileUpload } from '@wordpress/components';
911

1012
const MyFormFileUpload = () => (
11-
<FormFileUpload
12-
accept="image/*"
13-
onChange={ ( event ) => console.log( event.currentTarget.files ) }
14-
>
15-
Upload
16-
</FormFileUpload>
13+
<FormFileUpload
14+
__next40pxDefaultSize
15+
accept="image/*"
16+
onChange={ ( event ) => console.log( event.currentTarget.files ) }
17+
>
18+
Upload
19+
</FormFileUpload>
1720
);
1821
```
19-
2022
## Props
2123

22-
The component accepts the following props. Props not included in this set will be passed to the `Button` component.
24+
### `__next40pxDefaultSize`
25+
26+
Start opting into the larger default height that will become the default size in a future version.
27+
28+
- Type: `boolean`
29+
- Required: No
30+
- Default: `false`
2331

24-
### accept
32+
### `accept`
2533

26-
A string passed to `input` element that tells the browser which file types can be upload to the upload by the user use. e.g: `image/*,video/*`.
27-
More information about this string is available in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers.
34+
A string passed to the `input` element that tells the browser which
35+
[file types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers)
36+
can be uploaded by the user. e.g: `image/*,video/*`.
2837

29-
- Type: `String`
30-
- Required: No
38+
- Type: `string`
39+
- Required: No
3140

32-
### children
41+
### `children`
3342

3443
Children are passed as children of `Button`.
3544

36-
- Type: `Boolean`
37-
- Required: No
45+
- Type: `ReactNode`
46+
- Required: No
3847

39-
### icon
48+
### `icon`
4049

41-
The icon to render. Supported values are: Dashicons (specified as strings), functions, Component instances and `null`.
50+
The icon to render in the default button.
4251

43-
- Type: `String|Function|Component|null`
44-
- Required: No
45-
- Default: `null`
52+
See the `Icon` component docs for more information.
4653

47-
### multiple
54+
- Type: `IconType`
55+
- Required: No
56+
57+
### `multiple`
4858

4959
Whether to allow multiple selection of files or not.
5060

51-
- Type: `Boolean`
52-
- Required: No
53-
- Default: `false`
61+
- Type: `boolean`
62+
- Required: No
63+
- Default: `false`
5464

55-
### onChange
65+
### `onChange`
5666

5767
Callback function passed directly to the `input` file element.
5868

5969
Select files will be available in `event.currentTarget.files`.
6070

61-
- Type: `Function`
62-
- Required: Yes
71+
- Type: `ChangeEventHandler<HTMLInputElement>`
72+
- Required: Yes
6373

64-
### onClick
74+
### `onClick`
6575

6676
Callback function passed directly to the `input` file element.
6777

68-
This can be useful when you want to force a `change` event to fire when the user chooses the same file again. To do this, set the target value to an empty string in the `onClick` function.
78+
This can be useful when you want to force a `change` event to fire when
79+
the user chooses the same file again. To do this, set the target value to
80+
an empty string in the `onClick` function.
6981

7082
```jsx
7183
<FormFileUpload
72-
onClick={ ( event ) => ( event.target.value = '' ) }
73-
onChange={ onChange }
84+
__next40pxDefaultSize
85+
onClick={ ( event ) => ( event.target.value = '' ) }
86+
onChange={ onChange }
7487
>
75-
Upload
88+
Upload
7689
</FormFileUpload>
7790
```
7891

79-
- Type: `Function`
80-
- Required: No
81-
82-
### render
92+
- Type: `MouseEventHandler<HTMLInputElement>`
93+
- Required: No
8394

84-
Optional callback function used to render the UI. If passed, the component does not render the default UI (a button) and calls this function to render it. The function receives an object with property `openFileDialog`, a function that, when called, opens the browser native file upload modal window.
95+
### `render`
8596

86-
- Type: `Function`
87-
- Required: No
97+
Optional callback function used to render the UI.
8898

89-
### __next40pxDefaultSize
90-
91-
Start opting into the larger default height that will become the default size in a future version.
99+
If passed, the component does not render the default UI (a button) and
100+
calls this function to render it. The function receives an object with
101+
property `openFileDialog`, a function that, when called, opens the browser
102+
native file upload modal window.
92103

93-
- Type: `Boolean`
94-
- Required: No
95-
- Default: `false`
104+
- Type: `(arg: { openFileDialog: () => void; }) => ReactNode`
105+
- Required: No
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "../../schemas/docs-manifest.json",
3+
"displayName": "FormFileUpload",
4+
"filePath": "./index.tsx"
5+
}

packages/components/src/form-file-upload/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ import { useRef } from '@wordpress/element';
99
import Button from '../button';
1010
import type { WordPressComponentProps } from '../context';
1111
import type { FormFileUploadProps } from './types';
12+
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';
1213

1314
/**
14-
* FormFileUpload is a component that allows users to select files from their local device.
15+
* FormFileUpload allows users to select files from their local device.
1516
*
1617
* ```jsx
1718
* import { FormFileUpload } from '@wordpress/components';
1819
*
1920
* const MyFormFileUpload = () => (
2021
* <FormFileUpload
22+
* __next40pxDefaultSize
2123
* accept="image/*"
2224
* onChange={ ( event ) => console.log( event.currentTarget.files ) }
2325
* >
@@ -40,6 +42,15 @@ export function FormFileUpload( {
4042
ref.current?.click();
4143
};
4244

45+
if ( ! render ) {
46+
maybeWarnDeprecated36pxSize( {
47+
componentName: 'FormFileUpload',
48+
__next40pxDefaultSize: props.__next40pxDefaultSize,
49+
// @ts-expect-error - We don't "officially" support all Button props but this likely happens.
50+
size: props.size,
51+
} );
52+
}
53+
4354
const ui = render ? (
4455
render( { openFileDialog } )
4556
) : (

packages/components/src/form-file-upload/stories/index.story.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const Template: StoryFn< typeof FormFileUpload > = ( props ) => {
3636
export const Default = Template.bind( {} );
3737
Default.args = {
3838
children: 'Select file',
39+
__next40pxDefaultSize: true,
3940
};
4041

4142
export const RestrictFileTypes = Template.bind( {} );

packages/components/src/form-file-upload/test/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import userEvent from '@testing-library/user-event';
77
/**
88
* Internal dependencies
99
*/
10-
import FormFileUpload from '..';
10+
import _FormFileUpload from '..';
1111

1212
/**
1313
* Browser dependencies
1414
*/
1515
const { File } = window;
1616

17+
const FormFileUpload = (
18+
props: React.ComponentProps< typeof _FormFileUpload >
19+
) => <_FormFileUpload __next40pxDefaultSize { ...props } />;
20+
1721
// @testing-library/user-event considers changing <input type="file"> to a string as a change, but it do not occur on real browsers, so the comparisons will be against this result
1822
const fakePath = expect.objectContaining( {
1923
target: expect.objectContaining( {

packages/components/src/form-file-upload/types.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ export type FormFileUploadProps = {
1717
*/
1818
__next40pxDefaultSize?: boolean;
1919
/**
20-
* A string passed to `input` element that tells the browser which file types can be
21-
* upload to the upload by the user use. e.g: `image/*,video/*`.
22-
*
23-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers.
20+
* A string passed to the `input` element that tells the browser which
21+
* [file types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers)
22+
* can be uploaded by the user. e.g: `image/*,video/*`.
2423
*/
2524
accept?: InputHTMLAttributes< HTMLInputElement >[ 'accept' ];
2625
/**
2726
* Children are passed as children of `Button`.
2827
*/
2928
children?: ReactNode;
3029
/**
31-
* The icon to render in the `Button`.
30+
* The icon to render in the default button.
31+
*
32+
* See the `Icon` component docs for more information.
3233
*/
3334
icon?: ComponentProps< typeof Icon >[ 'icon' ];
3435
/**
@@ -50,10 +51,11 @@ export type FormFileUploadProps = {
5051
*
5152
* ```jsx
5253
* <FormFileUpload
53-
* onClick={ ( event ) => ( event.target.value = '' ) }
54-
* onChange={ onChange }
54+
* __next40pxDefaultSize
55+
* onClick={ ( event ) => ( event.target.value = '' ) }
56+
* onChange={ onChange }
5557
* >
56-
* Upload
58+
* Upload
5759
* </FormFileUpload>
5860
* ```
5961
*/

0 commit comments

Comments
 (0)