Skip to content

Commit

Permalink
Merge branch 'trunk' into add/61447-upload-media-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Dec 2, 2024
2 parents 93e9ec9 + 92c12fe commit 6176a66
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`AlignmentUI should allow custom alignment controls to be specified 1`]
align="custom-left"
aria-label="My custom left"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -35,7 +35,7 @@ exports[`AlignmentUI should allow custom alignment controls to be specified 1`]
align="custom-right"
aria-label="My custom right"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down Expand Up @@ -100,7 +100,7 @@ exports[`AlignmentUI should match snapshot when controls are visible 1`] = `
align="left"
aria-label="Align text left"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -123,7 +123,7 @@ exports[`AlignmentUI should match snapshot when controls are visible 1`] = `
align="center"
aria-label="Align text center"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -146,7 +146,7 @@ exports[`AlignmentUI should match snapshot when controls are visible 1`] = `
align="right"
aria-label="Align text right"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="None"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -64,7 +64,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="Align left"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -86,7 +86,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="Align center"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -108,7 +108,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="Align right"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`BlockVerticalAlignmentUI should match snapshot when controls are visibl
<button
aria-label="Align top"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -64,7 +64,7 @@ exports[`BlockVerticalAlignmentUI should match snapshot when controls are visibl
<button
aria-label="Align middle"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -86,7 +86,7 @@ exports[`BlockVerticalAlignmentUI should match snapshot when controls are visibl
<button
aria-label="Align bottom"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down
27 changes: 15 additions & 12 deletions packages/block-editor/src/components/iframe/use-scale-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* WordPress dependencies
*/
import { useEffect, useRef, useCallback } from '@wordpress/element';
import {
usePrevious,
useReducedMotion,
useResizeObserver,
} from '@wordpress/compose';
import { useReducedMotion, useResizeObserver } from '@wordpress/compose';

/**
* @typedef {Object} TransitionState
Expand Down Expand Up @@ -284,28 +280,35 @@ export function useScaleCanvas( {
transitionFromRef.current = transitionToRef.current;
}, [ iframeDocument ] );

const previousIsZoomedOut = usePrevious( isZoomedOut );
const previousIsZoomedOut = useRef( false );

/**
* Runs when zoom out mode is toggled, and sets the startAnimation flag
* so the animation will start when the next useEffect runs. We _only_
* want to animate when the zoom out mode is toggled, not when the scale
* changes due to the container resizing.
*/
useEffect( () => {
if ( ! iframeDocument || previousIsZoomedOut === isZoomedOut ) {
return;
}
const trigger =
iframeDocument && previousIsZoomedOut.current !== isZoomedOut;

if ( isZoomedOut ) {
iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
previousIsZoomedOut.current = isZoomedOut;

if ( ! trigger ) {
return;
}

startAnimationRef.current = true;

if ( ! isZoomedOut ) {
return;
}

iframeDocument.documentElement.classList.add( 'is-zoomed-out' );
return () => {
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
};
}, [ iframeDocument, isZoomedOut, previousIsZoomedOut ] );
}, [ iframeDocument, isZoomedOut ] );

/**
* This handles:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ This component is used for blocks that display text, commonly inside a
Renders a letter spacing control.

```jsx
import { LetterSpacingControl } from '@wordpress/block-editor';
import { __experimentalLetterSpacingControl as LetterSpacingControl } from '@wordpress/block-editor';

const MyLetterSpacingControl = () => (
<LetterSpacingControl
value={ value }
onChange={ onChange }
__unstableInputWidth="auto"
__next40pxDefaultSize
/>
);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
__experimentalUnitControl as UnitControl,
__experimentalUseCustomUnits as useCustomUnits,
} from '@wordpress/components';
import deprecated from '@wordpress/deprecated';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -35,9 +36,25 @@ export default function LetterSpacingControl( {
availableUnits: availableUnits || [ 'px', 'em', 'rem' ],
defaultValues: { px: 2, em: 0.2, rem: 0.2 },
} );

if (
! __next40pxDefaultSize &&
( otherProps.size === undefined || otherProps.size === 'default' )
) {
deprecated(
`36px default size for wp.blockEditor.__experimentalLetterSpacingControl`,
{
since: '6.8',
version: '7.1',
hint: 'Set the `__next40pxDefaultSize` prop to true to start opting into the new default size, which will become the default in a future version.',
}
);
}

return (
<UnitControl
__next40pxDefaultSize={ __next40pxDefaultSize }
__shouldNotWarnDeprecated36pxSize
{ ...otherProps }
label={ __( 'Letter spacing' ) }
value={ value }
Expand Down
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `CustomSelectControl`: Deprecate 36px default size ([#67441](https://github.com/WordPress/gutenberg/pull/67441)).
- `NumberControl`: Deprecate 36px default size ([#66730](https://github.com/WordPress/gutenberg/pull/66730)).
- `UnitControl`: Deprecate 36px default size ([#66791](https://github.com/WordPress/gutenberg/pull/66791)).
- `FormFileUpload`: Deprecate 36px default size ([#67438](https://github.com/WordPress/gutenberg/pull/67438)).

### Enhancements

Expand All @@ -25,6 +26,7 @@

- Upgraded `@ariakit/react` (v0.4.13) and `@ariakit/test` (v0.4.5) ([#65907](https://github.com/WordPress/gutenberg/pull/65907)).
- Upgraded `@ariakit/react` (v0.4.15) and `@ariakit/test` (v0.4.7) ([#67404](https://github.com/WordPress/gutenberg/pull/67404)).
- `ToolbarButton`: Set size to "compact" ([#67440](https://github.com/WordPress/gutenberg/pull/67440)).
- Exported the `WPCompleter` type as it was being used in block-editor/autocompleters ([#67410](https://github.com/WordPress/gutenberg/pull/67410)).
- `SlotFill`: remove manual rerenders from the portal `Fill` component ([#67471](https://github.com/WordPress/gutenberg/pull/67471)).

Expand Down
106 changes: 58 additions & 48 deletions packages/components/src/form-file-upload/README.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,105 @@
# FormFileUpload

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

## Usage
<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>

FormFileUpload allows users to select files from their local device.

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

const MyFormFileUpload = () => (
<FormFileUpload
accept="image/*"
onChange={ ( event ) => console.log( event.currentTarget.files ) }
>
Upload
</FormFileUpload>
<FormFileUpload
__next40pxDefaultSize
accept="image/*"
onChange={ ( event ) => console.log( event.currentTarget.files ) }
>
Upload
</FormFileUpload>
);
```

## Props

The component accepts the following props. Props not included in this set will be passed to the `Button` component.
### `__next40pxDefaultSize`

Start opting into the larger default height that will become the default size in a future version.

- Type: `boolean`
- Required: No
- Default: `false`

### accept
### `accept`

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/*`.
More information about this string is available in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers.
A string passed to the `input` element that tells the browser which
[file types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers)
can be uploaded by the user. e.g: `image/*,video/*`.

- Type: `String`
- Required: No
- Type: `string`
- Required: No

### children
### `children`

Children are passed as children of `Button`.

- Type: `Boolean`
- Required: No
- Type: `ReactNode`
- Required: No

### icon
### `icon`

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

- Type: `String|Function|Component|null`
- Required: No
- Default: `null`
See the `Icon` component docs for more information.

### multiple
- Type: `IconType`
- Required: No

### `multiple`

Whether to allow multiple selection of files or not.

- Type: `Boolean`
- Required: No
- Default: `false`
- Type: `boolean`
- Required: No
- Default: `false`

### onChange
### `onChange`

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

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

- Type: `Function`
- Required: Yes
- Type: `ChangeEventHandler<HTMLInputElement>`
- Required: Yes

### onClick
### `onClick`

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

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.
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.

```jsx
<FormFileUpload
onClick={ ( event ) => ( event.target.value = '' ) }
onChange={ onChange }
__next40pxDefaultSize
onClick={ ( event ) => ( event.target.value = '' ) }
onChange={ onChange }
>
Upload
Upload
</FormFileUpload>
```

- Type: `Function`
- Required: No

### render
- Type: `MouseEventHandler<HTMLInputElement>`
- Required: No

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.
### `render`

- Type: `Function`
- Required: No
Optional callback function used to render the UI.

### __next40pxDefaultSize

Start opting into the larger default height that will become the default size in a future version.
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.

- Type: `Boolean`
- Required: No
- Default: `false`
- Type: `(arg: { openFileDialog: () => void; }) => ReactNode`
- Required: No
5 changes: 5 additions & 0 deletions packages/components/src/form-file-upload/docs-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "../../schemas/docs-manifest.json",
"displayName": "FormFileUpload",
"filePath": "./index.tsx"
}
Loading

0 comments on commit 6176a66

Please sign in to comment.