Skip to content

Commit

Permalink
Render shape action on tool selected (excalidraw#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fausto95 authored and vjeux committed Jan 18, 2020
1 parent 5563dd3 commit bbabf33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/actions/actionProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const actionChangeStrokeColor: Action = {
<h5>Stroke</h5>
<ColorPicker
type="elementStroke"
color={getSelectedAttribute(elements, element => element.strokeColor)}
color={
getSelectedAttribute(elements, element => element.strokeColor) ||
appState.currentItemStrokeColor
}
onChange={updateData}
/>
</>
Expand All @@ -54,15 +57,15 @@ export const actionChangeBackgroundColor: Action = {
appState: { ...appState, currentItemBackgroundColor: value }
};
},
PanelComponent: ({ elements, updateData }) => (
PanelComponent: ({ elements, appState, updateData }) => (
<>
<h5>Background</h5>
<ColorPicker
type="elementBackground"
color={getSelectedAttribute(
elements,
element => element.backgroundColor
)}
color={
getSelectedAttribute(elements, element => element.backgroundColor) ||
appState.currentItemBackgroundColor
}
onChange={updateData}
/>
</>
Expand Down
14 changes: 10 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,12 @@ export class App extends React.Component<{}, AppState> {
};

private renderSelectedShapeActions(elements: readonly ExcalidrawElement[]) {
const { elementType } = this.state;
const selectedElements = elements.filter(el => el.isSelected);
if (selectedElements.length === 0) {
const hasSelectedElements = selectedElements.length > 0;
const isTextToolSelected = elementType === "text";
const isShapeToolSelected = elementType !== "selection";
if (!(hasSelectedElements || isShapeToolSelected || isTextToolSelected)) {
return null;
}

Expand All @@ -358,7 +362,8 @@ export class App extends React.Component<{}, AppState> {
this.syncActionResult
)}

{hasBackground(elements) && (
{(hasBackground(elements) ||
(isShapeToolSelected && !isTextToolSelected)) && (
<>
{this.actionManager.renderAction(
"changeBackgroundColor",
Expand All @@ -377,7 +382,8 @@ export class App extends React.Component<{}, AppState> {
</>
)}

{hasStroke(elements) && (
{(hasStroke(elements) ||
(isShapeToolSelected && !isTextToolSelected)) && (
<>
{this.actionManager.renderAction(
"changeStrokeWidth",
Expand All @@ -396,7 +402,7 @@ export class App extends React.Component<{}, AppState> {
</>
)}

{hasText(elements) && (
{(hasText(elements) || isTextToolSelected) && (
<>
{this.actionManager.renderAction(
"changeFontSize",
Expand Down

0 comments on commit bbabf33

Please sign in to comment.