Skip to content

Commit

Permalink
fix(padding): remove global group parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Jul 29, 2022
1 parent 91e3365 commit 563421c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/components/QuestionMark.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, PropsWithChildren } from 'react';
import styled from 'styled-components';

import Tooltip from './Tooltip';
Expand All @@ -7,7 +7,9 @@ interface Props {
hover?: boolean;
}

export const QuestionMark: FunctionComponent<Props> = (props) => (
export const QuestionMark: FunctionComponent<PropsWithChildren<Props>> = (
props
) => (
<Tooltip
hover={props.hover}
handler={React.forwardRef<HTMLDivElement, unknown>((_, ref) => (
Expand Down
15 changes: 10 additions & 5 deletions src/main/padding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const getPadding = (node: SceneNode) => {

EventEmitter.on('remove padding', async ({ direction }) => {
const state = await getState();

if (figma.currentPage.selection.length === 1) {
const currentNode = figma.currentPage.selection[0];

Expand Down Expand Up @@ -82,7 +83,7 @@ EventEmitter.on('add padding', async ({ direction, settings }) => {

const { lockDetachedGroup, lockAttachedGroup, ...nodeSettings } = settings;

const nodeData = getNodeAndParentNode(currentNode, state.isGlobalGroup);
const nodeData = getNodeAndParentNode(currentNode, undefined);

switch (nodeData.error) {
case ParentNodeErrors.PARENT_NOT_FOUND:
Expand Down Expand Up @@ -171,12 +172,14 @@ EventEmitter.on('add padding', async ({ direction, settings }) => {
nodes: paddingLines,
name: GROUP_NAME_DETACHED,
locked: lockDetachedGroup,
isGlobalGroup: state.isGlobalGroup,
});
} else {
appendElementsToGroup({
node: currentNode,
nodes: paddingLines,
locked: lockAttachedGroup,
isGlobalGroup: state.isGlobalGroup,
});
}

Expand Down Expand Up @@ -217,15 +220,17 @@ export enum ParentNodeErrors {

export const getNodeAndParentNode = (
node?: SceneNode,
parentNode?: SceneNode,
isGlobalGroup?: boolean
parentNode?: SceneNode
): { node?: SceneNode; parentNode?: SceneNode; error: ParentNodeErrors } => {
let currentNode = node ?? (figma.currentPage.selection[0] as SceneNode);

if (parentNode && (parentNode as any).type === 'PAGE') {
return { error: ParentNodeErrors.PARENT_NOT_FOUND };
}

if (figma.currentPage.selection.length === 1 && !parentNode) {
if (currentNode.parent && currentNode.parent.type !== 'PAGE') {
parentNode = getNearestParentNode(currentNode, isGlobalGroup);
console.log(parentNode);
parentNode = getNearestParentNode(currentNode);
} else {
return { error: ParentNodeErrors.PARENT_NOT_FOUND };
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const Settings: FunctionComponent = observer(() => {
<Toggle
checked={store.isGlobalGroup}
label="Use a global group"
description="Groups all measurements in one global group"
description="All measurements in one group per page"
onChange={() => store.toggleIsGlobalGroup()}
/>
<Toggle
Expand Down

0 comments on commit 563421c

Please sign in to comment.