|
| 1 | + |
| 2 | +/* |
| 3 | + * Copyright 2019, GeoSolutions Sas. |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * This source code is licensed under the BSD-style license found in the |
| 7 | + * LICENSE file in the root directory of this source tree. |
| 8 | + */ |
| 9 | + |
| 10 | +import React from "react"; |
| 11 | +import Toolbar from '../../misc/toolbar/Toolbar'; |
| 12 | +import ToolbarDropdownButton from '../common/ToolbarDropdownButton'; |
| 13 | +import Message from '../../I18N/Message'; |
| 14 | + |
| 15 | +const toolButtons = { |
| 16 | + size: ({ size, update }) => ({ |
| 17 | + Element: () => <ToolbarDropdownButton |
| 18 | + value={size} |
| 19 | + glyph="resize-horizontal" |
| 20 | + tooltipId="geostory.contentToolbar.contentSize" |
| 21 | + options={[{ |
| 22 | + value: 'small', |
| 23 | + label: <Message msgId="geostory.contentToolbar.smallSizeLabel"/> |
| 24 | + }, { |
| 25 | + value: 'medium', |
| 26 | + label: <Message msgId="geostory.contentToolbar.mediumSizeLabel"/> |
| 27 | + }, { |
| 28 | + value: 'large', |
| 29 | + label: <Message msgId="geostory.contentToolbar.largeSizeLabel"/> |
| 30 | + }, { |
| 31 | + value: 'full', |
| 32 | + label: <Message msgId="geostory.contentToolbar.fullSizeLabel"/> |
| 33 | + }]} |
| 34 | + onSelect={(selected) => update('size', selected)}/> |
| 35 | + }), |
| 36 | + align: ({ size, align, update }) => ({ |
| 37 | + Element: () => <ToolbarDropdownButton |
| 38 | + value={align} |
| 39 | + disabled={size === 'full'} |
| 40 | + glyph="align-center" |
| 41 | + tooltipId="geostory.contentToolbar.contentAlign" |
| 42 | + options={[{ |
| 43 | + value: 'left', |
| 44 | + label: <Message msgId="geostory.contentToolbar.leftAlignLabel"/>, |
| 45 | + glyph: 'align-left' |
| 46 | + }, { |
| 47 | + value: 'center', |
| 48 | + label: <Message msgId="geostory.contentToolbar.centerAlignLabel"/>, |
| 49 | + glyph: 'align-center' |
| 50 | + }, { |
| 51 | + value: 'right', |
| 52 | + label: <Message msgId="geostory.contentToolbar.rightAlignLabel"/>, |
| 53 | + glyph: 'align-right' |
| 54 | + }]} |
| 55 | + onSelect={(selected) => update('align', selected)}/> |
| 56 | + }), |
| 57 | + theme: ({ theme, update }) => ({ |
| 58 | + Element: () => <ToolbarDropdownButton |
| 59 | + value={theme} |
| 60 | + glyph="dropper" |
| 61 | + tooltipId="geostory.contentToolbar.contentTheme" |
| 62 | + options={[{ |
| 63 | + value: 'bright', |
| 64 | + label: <Message msgId="geostory.contentToolbar.brightThemeLabel"/> |
| 65 | + }, { |
| 66 | + value: 'bright-text', |
| 67 | + label: <Message msgId="geostory.contentToolbar.brightTextThemeLabel"/> |
| 68 | + }, { |
| 69 | + value: 'dark', |
| 70 | + label: <Message msgId="geostory.contentToolbar.darkThemeLabel"/> |
| 71 | + }, { |
| 72 | + value: 'dark-text', |
| 73 | + label: <Message msgId="geostory.contentToolbar.darkTextThemeLabel"/> |
| 74 | + }]} |
| 75 | + onSelect={(selected) => update('theme', selected)}/> |
| 76 | + }) |
| 77 | +}; |
| 78 | +/** |
| 79 | + * Toolbar to update properties of content, |
| 80 | + * @prop {array} tools list of tool's names to display in the edit toolbar, available tools `size`, `align` and `theme` |
| 81 | + * @prop {string} size one of `small`, `medium`, `large` and `full` |
| 82 | + * @prop {string} align one of `left`, `center` and `right` |
| 83 | + * @prop {string} theme one of `bright`, `bright-text`, `dark` and `dark-text` |
| 84 | + * @prop {function} update handler for select properties events, parameters (key, value) |
| 85 | + * @example |
| 86 | + */ |
| 87 | +export default function ContentToolbar({ |
| 88 | + tools = [], |
| 89 | + ...props |
| 90 | +}) { |
| 91 | + return ( |
| 92 | + <div className="ms-content-toolbar"> |
| 93 | + <Toolbar |
| 94 | + btnDefaultProps={{ |
| 95 | + className: 'square-button-md no-border' |
| 96 | + }} |
| 97 | + buttons={tools |
| 98 | + .filter((id) => toolButtons[id]) |
| 99 | + .map(id => toolButtons[id](props))}/> |
| 100 | + </div> |
| 101 | + ); |
| 102 | +} |
0 commit comments