Skip to content

Commit

Permalink
Merge pull request #7616 from ckeditor/i/7559
Browse files Browse the repository at this point in the history
Internal (image): Improved the `ImageResizeUI` plugin UI. Added dedicated icons for each option (small, medium, large and original) and the dropdown (dropdown icon). Closes #7559.

Internal (image): Improved the screen reader experience for the `ImageResizeUI` standalone buttons configured via `config.image.toolbar` (see #7559).

Other (core): Added icons that represent different sizes of an object (`object-size-*.svg`) (see #7559).
  • Loading branch information
oleq committed Jul 17, 2020
2 parents 84e2042 + 7f2b25e commit 565628a
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 188 deletions.
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-full.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-large.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-medium.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/ckeditor5-core/theme/icons/object-size-small.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -17,26 +17,29 @@ ClassicEditor
resizeOptions: [
{
name: 'imageResize:original',
label: 'Original size',
value: null
label: 'Original',
value: null,
icon: 'original'
},
{
name: 'imageResize:50',
label: '50%',
value: '50'
value: '50',
icon: 'medium'
},
{
name: 'imageResize:75',
label: '75%',
value: '75'
value: '75',
icon: 'large'
}
],
toolbar: [
'imageStyle:full',
'imageStyle:side', '|',
'imageResize:original',
'imageResize:50',
'imageResize:75'
'imageResize:75',
'imageResize:original'
]
},
cloudServices: CS_CONFIG
Expand Down
Expand Up @@ -17,7 +17,7 @@ ClassicEditor
resizeOptions: [
{
name: 'imageResize:original',
label: 'Original size',
label: 'Original',
value: null
},
{
Expand Down
8 changes: 5 additions & 3 deletions packages/ckeditor5-image/lang/contexts.json
Expand Up @@ -11,7 +11,9 @@
"Insert image": "Label for the insert image toolbar button.",
"Upload failed": "Title of the notification displayed when upload fails.",
"Image toolbar": "The label used by assistive technologies describing an image toolbar attached to an image widget.",
"Resize image to": "The label used for the standalone resize option buttons in the image toolbar",
"Resize image": "The label used for the dropdown in the image toolbar, containing defined resize options",
"Resize image to the original size": "The label used for the standalone resize reset option button in the image toolbar, when user set the value to `null`"
"Resize image": "The label used for the dropdown in the image toolbar containing defined resize options",
"Resize image to %0": "The label used for the standalone resize options buttons in the image toolbar",
"Resize image to the original size": "The accessibility label of the standalone image resize reset option button in the image toolbar for the screen readers",
"Original": "Default label for the resize option that resets the size of the image.",
"Image resize list": "The accessibility label of the image resize dropdown list for the screen readers."
}
88 changes: 66 additions & 22 deletions packages/ckeditor5-image/src/imageresize.js
Expand Up @@ -58,16 +58,21 @@ export default class ImageResize extends Plugin {
*/

/**
* The resize options.
* The image resize options.
*
* Each option should have its `name`, which is a component name definition that will be
* used in the {@link module:image/imageresize/imageresizeui~ImageResizeUI} plugin.
* Other properties like `label` and `value` define the following:
* a text label for the option button and the value that will be applied to the image's width.
* Each option should have at least these two properties:
*
* The value property is combined with the `resizeUnit` (`%` by default), eg: `value: '50'` and `resizeUnit: '%'` is `50%`.
* * name: The name of the UI component registered in the global
* {@link module:core/editor/editorui~EditorUI#componentFactory component factory} of the editor,
* representing the button a user can click to change the size of an image,
* * value: An actual image width applied when a user clicks the mentioned button
* ({@link module:image/imageresize/imageresizecommand~ImageResizeCommand} gets executed).
* The value property is combined with the {@link module:image/image~ImageConfig#resizeUnit `config.image.resizeUnit`} (`%` by default).
* For instance: `value: '50'` and `resizeUnit: '%'` will render as `'50%'` in the UI.
*
* **NOTE:** If you want to set an option that will reset image to its original size, you need to pass a `null` value
* **Resetting the image size**
*
* If you want to set an option that will reset image to its original size, you need to pass a `null` value
* to one of the options. The `:original` token is not mandatory, you can call it anything you wish, but it must reflect
* in the standalone buttons configuration for the image toolbar.
*
Expand All @@ -77,45 +82,41 @@ export default class ImageResize extends Plugin {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* label: 'Original size',
* value: null
* },
* {
* name: 'imageResize:50',
* label: '50%',
* value: '50'
* },
* {
* name: 'imageResize:75',
* label: '75%',
* value: '75'
* } ]
* }
* } )
* .then( ... )
* .catch( ... );
*
* **Resizing images using a dropdown**
*
* With resize options defined, you can decide whether you want to display them as a dropdown or as standalone buttons.
* For the dropdown, you need to pass only the `imageResize` token to the `image.toolbar`.
* The dropdown contains all defined options by default:
* For the dropdown, you need to pass only the `imageResize` token to the
{@link module:image/image~ImageConfig#toolbar `config.image.toolbar`}. The dropdown contains all defined options by default:
*
* ClassicEditor
* ClassicEditor
* .create( editorElement, {
* image: {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* label: 'Original size',
* value: null
* },
* {
* name: 'imageResize:50',
* label: '50%',
* value: '50'
* },
* {
* name: 'imageResize:75',
* label: '75%',
* value: '75'
* } ],
* toolbar: [ 'imageResize', ... ],
Expand All @@ -124,33 +125,76 @@ export default class ImageResize extends Plugin {
* .then( ... )
* .catch( ... );
*
* If you want to have separate buttons for each option, pass their names instead:
* **Resizing images using individual buttons**
*
* If you want to have separate buttons for {@link module:image/imageresize/imageresizeui~ImageResizeOption each option},
* pass their names to the {@link module:image/image~ImageConfig#toolbar `config.image.toolbar`} instead. Please keep in mind
* that this time **you must define the additional
* {@link module:image/imageresize/imageresizeui~ImageResizeOption `icon` property}**:
*
* ClassicEditor
* ClassicEditor
* .create( editorElement, {
* image: {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* label: 'Original size',
* value: null
* icon: 'original'
* },
* {
* name: 'imageResize:25',
* value: '25'
* icon: 'small'
* },
* {
* name: 'imageResize:50',
* label: '50%',
* value: '50'
* icon: 'medium'
* },
* {
* name: 'imageResize:75',
* label: '75%',
* value: '75'
* icon: 'large'
* } ],
* toolbar: [ 'imageResize:original', 'imageResize:50', 'imageResize:75', ... ],
* toolbar: [ 'imageResize:25', 'imageResize:50', 'imageResize:75', 'imageResize:original', ... ],
* }
* } )
* .then( ... )
* .catch( ... );
*
* **Customizing resize button labels**
*
* You can set your own label for each resize button. To do that, add the `label` property like in the example below.
*
* * When using the **dropdown**, the labels are displayed on the list of all options when you open the dropdown.
* * When using **standalone buttons**, the labels will are displayed as tooltips when a user hovers over the button.
*
* ClassicEditor
* .create( editorElement, {
* image: {
* resizeUnit: "%",
* resizeOptions: [ {
* name: 'imageResize:original',
* value: null,
* label: 'Original size'
* // Note: add the "icon" property if you're configuring a standalone button.
* },
* {
* name: 'imageResize:50',
* value: '50',
* label: 'Medium size'
* // Note: add the "icon" property if you're configuring a standalone button.
* },
* {
* name: 'imageResize:75',
* value: '75',
* label: 'Large size'
* // Note: add the "icon" property if you're configuring a standalone button.
* } ]
* }
* } )
* .then( ... )
* .catch( ... );
*
* @member {Array.<module:image/imageresize/imageresizeui~ImageResizeOption>} module:image/image~ImageConfig#resizeOptions
*/
Expand Up @@ -4,7 +4,7 @@
*/

/**
* @module image/imageresizeediting
* @module image/imageresize/imageresizeediting
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
Expand Down

0 comments on commit 565628a

Please sign in to comment.