Skip to content

Commit

Permalink
fix: row link class anchor in anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 27, 2021
1 parent 09d5f92 commit 1a20fc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions ui/blocks/src/ComponentJSX/ComponentJSXTree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable react/display-name */
import React, { FC, useMemo, useEffect, useReducer } from 'react';
import { Box } from 'theme-ui';
import { TriangleDownIcon } from '@primer/octicons-react';
import { Component, JSXTree, isLocalImport } from '@component-controls/core';
import { usePackage } from '@component-controls/store';
Expand Down Expand Up @@ -94,8 +95,8 @@ export const ComponentJSXTree: FC<ComponentJSXTreeProps> = ({ component }) => {
const { dependencies, devDependencies } = componentPackage || {};
const treeToItems = (
tree: JSXTree,
level: number = 0,
parentIndex: number = 0,
level = 0,
parentIndex = 0,
): TreeItems | undefined => {
return tree.length
? tree.map((item, index) => ({
Expand Down Expand Up @@ -176,6 +177,7 @@ export const ComponentJSXTree: FC<ComponentJSXTreeProps> = ({ component }) => {
items={rows}
chevronIcon={<TriangleDownIcon />}
indentPixels={16}
rowLinkClass={Box}
/>
</ActionContainer>
) : null;
Expand Down
8 changes: 4 additions & 4 deletions ui/components/src/Tree/Tree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsx jsx */
import { FC, useEffect, useState } from 'react';
import { FC, ElementType, useEffect, useState } from 'react';
import { jsx, Box, Flex, Text, Button, BoxProps, ButtonProps } from 'theme-ui';
import { ChevronDownIcon } from '@primer/octicons-react';
import {
Expand Down Expand Up @@ -35,6 +35,7 @@ export const Tree: FC<TreeProps> = ({
onExpandCollapse,
arrowPosition = 'end',
chevronIcon = <ChevronDownIcon />,
rowLinkClass,
indentPixels = 8,
...rest
}) => {
Expand Down Expand Up @@ -93,9 +94,8 @@ export const Tree: FC<TreeProps> = ({
const itemId = id || label;
const isExpanded: boolean =
expandedItems && itemId ? expandedItems.includes(item) : false;
const LinkClass: LinkClassType | FC<ButtonProps> = itemItems
? Button
: Link;
const LinkClass: LinkClassType | FC<ButtonProps> | ElementType =
rowLinkClass || (itemItems ? Button : Link);
const itemKey = `item_${itemId}_${level}`;

const isActiveItem = activeItem && activeItem.id === id;
Expand Down
7 changes: 6 additions & 1 deletion ui/components/src/Tree/tree-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode } from 'react';
import React, { ReactNode } from 'react';

type NavLabelFn = (props: TreeItem & { isExpanded: boolean }) => ReactNode;

Expand Down Expand Up @@ -202,6 +202,11 @@ export type TreeOwnProps = {
* indentation in pixels for each elevel, By default 6 pixels
*/
indentPixels?: number;

/**
* row link class - to avoid anchor in anchor warning
*/
rowLinkClass?: React.ElementType;
};

export interface TreeState {
Expand Down

0 comments on commit 1a20fc2

Please sign in to comment.