Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing the active tool color via props. #168

Merged
merged 3 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
| toolbarProps.position | `right` | one of `none`, `top`, `right`, `bottom`, `left` | Toolbar position |
| toolbarProps.SVGAlignX | `left` | one of `left`, `center`, `right` | X Alignment used for "Fit to Viewer" action |
| toolbarProps.SVGAlignY | `top` | one of `top`, `center`, `bottom` | Y Alignment used for "Fit to Viewer" action |
| toolbarProps.activeToolColor | `#1CA6FC` | String | Color of active and hovered tool icons |

\* handler available only with the tool `none` or `auto`

Expand Down
3 changes: 2 additions & 1 deletion src/ui-toolbar/toolbar-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class ToolbarButton extends React.Component {
width: "24px",
height: "24px",
margin: [POSITION_TOP, POSITION_BOTTOM].indexOf(this.props.toolbarPosition) >= 0 ? "2px 1px" : "1px 2px",
color: this.props.active || this.state.hover ? '#1CA6FC' : '#FFF',
color: this.props.active || this.state.hover ? this.props.activeColor : '#FFF',
transition: "color 200ms ease",
background: "none",
padding: "0px",
Expand Down Expand Up @@ -72,6 +72,7 @@ ToolbarButton.propTypes = {
title: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
toolbarPosition: PropTypes.string.isRequired,
activeColor: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
active: PropTypes.bool.isRequired
};
11 changes: 9 additions & 2 deletions src/ui-toolbar/toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import IconZoomOut from './icon-zoom-out';
import IconFit from './icon-fit';
import ToolbarButton from './toolbar-button';

export default function Toolbar({tool, value, onChangeValue, onChangeTool, position, SVGAlignX, SVGAlignY}) {
export default function Toolbar({tool, value, onChangeValue, onChangeTool, activeToolColor, position, SVGAlignX, SVGAlignY}) {

let handleChangeTool = (event, tool) => {
onChangeTool(tool);
Expand Down Expand Up @@ -52,6 +52,7 @@ export default function Toolbar({tool, value, onChangeValue, onChangeTool, posit
<ToolbarButton
toolbarPosition={position}
active={tool === TOOL_NONE}
activeColor={activeToolColor}
name="unselect-tools"
title="Selection"
onClick={ event => handleChangeTool(event, TOOL_NONE) }>
Expand All @@ -61,6 +62,7 @@ export default function Toolbar({tool, value, onChangeValue, onChangeTool, posit
<ToolbarButton
toolbarPosition={position}
active={tool === TOOL_PAN}
activeColor={activeToolColor}
name="select-tool-pan"
title="Pan"
onClick={ event => handleChangeTool(event, TOOL_PAN) }>
Expand All @@ -70,6 +72,7 @@ export default function Toolbar({tool, value, onChangeValue, onChangeTool, posit
<ToolbarButton
toolbarPosition={position}
active={tool === TOOL_ZOOM_IN}
activeColor={activeToolColor}
name="select-tool-zoom-in"
title="Zoom in"
onClick={ event => handleChangeTool(event, TOOL_ZOOM_IN) }>
Expand All @@ -79,6 +82,7 @@ export default function Toolbar({tool, value, onChangeValue, onChangeTool, posit
<ToolbarButton
toolbarPosition={position}
active={tool === TOOL_ZOOM_OUT}
activeColor={activeToolColor}
name="select-tool-zoom-out"
title="Zoom out"
onClick={ event => handleChangeTool(event, TOOL_ZOOM_OUT) }>
Expand All @@ -88,6 +92,7 @@ export default function Toolbar({tool, value, onChangeValue, onChangeTool, posit
<ToolbarButton
toolbarPosition={position}
active={false}
activeColor={activeToolColor}
name="fit-to-viewer"
title="Fit to viewer"
onClick={ event => handleFit(event) }>
Expand All @@ -107,10 +112,12 @@ Toolbar.propTypes = {
position: PropTypes.oneOf([POSITION_TOP, POSITION_RIGHT, POSITION_BOTTOM, POSITION_LEFT]),
SVGAlignX: PropTypes.oneOf([ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT]),
SVGAlignY: PropTypes.oneOf([ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM]),
activeToolColor: PropTypes.string
};

Toolbar.defaultProps = {
position: POSITION_RIGHT,
SVGAlignX: ALIGN_LEFT,
SVGAlignY: ALIGN_TOP
SVGAlignY: ALIGN_TOP,
activeToolColor: '#1CA6FC'
};
1 change: 1 addition & 0 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ ReactSVGPanZoom.propTypes = {
position: PropTypes.oneOf([POSITION_NONE, POSITION_TOP, POSITION_RIGHT, POSITION_BOTTOM, POSITION_LEFT]),
SVGAlignX: PropTypes.oneOf([ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT]),
SVGAlignY: PropTypes.oneOf([ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM]),
activeToolColor: PropTypes.string,
}),

/**************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions storybook/stories/ViewerStory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export default class MainStory extends Component {
[ALIGN_CENTER]: ALIGN_CENTER,
[ALIGN_BOTTOM]: ALIGN_BOTTOM
}, ALIGN_TOP),

activeToolColor: color('toolbarProps.activeToolColor', '#1CA6FC'),
}}

miniatureProps={{
Expand Down