Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

feat: flat Tree component#1779

Merged
silviuaavram merged 59 commits intomasterfrom
feat/flat-tree-component
Aug 30, 2019
Merged

feat: flat Tree component#1779
silviuaavram merged 59 commits intomasterfrom
feat/flat-tree-component

Conversation

@silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Aug 9, 2019

Since now this tree may be virtualized, subtree open/closed state should be kept only on the main Tree, as other Items/Titles/Trees can be removed during the virtualisation process. Also removed sub-trees altogether and kept only the first Tree.

The Tree renders TreeItems which in turn render TreeTitles. open/close logic is kept on the main Tree state in a Map. Each item has an id (map key) and we keep its ref and open/close state as map object value.

At Tree constructor time, all items will receive props that should not be changed by the user, as they are used in aria attribute generation, keyboard navigation and collapsing/expansion. These are: level, siblings, index, parent. Each item will receive these props.

Each item will pass level, treeSize, index to the TreeTitle (for aria attribute generation in the behavior).

id is now required from the user for reach tree item.


static getDerivedStateFromProps(props: TreeItemProps) {
return {
hasSubtree: Tree.hasSubtree(props),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR in packages/react/dist/es/components/Tree/Tree.js -> packages/react/dist/es/components/Tree/TreeItem.js -> packages/react/dist/es/components/Tree/Tree.js

This create a circular reference, I suggest to create a simple function as there are no context requirements and move it to Tree/lib/hasSubtree.ts:

Suggested change
hasSubtree: Tree.hasSubtree(props),
hasSubtree: hasSubtree(props),


export default (siteVars: any): TreeTitleVariables => {
return {
defaultColor: siteVars.colors.grey[750],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://stardust-ui.github.io/react/color-schemes
This color perfectly maps foreground from default, can we use it? And we will be to remove variable overrides in Dark and HC themes.

I also suggest to rename it to color to match our variable naming convention:

Suggested change
defaultColor: siteVars.colors.grey[750],
color: siteVars.colorScheme.default.foreground,

@@ -0,0 +1,7 @@
import { TreeTitleVariables } from '../../../teams/components/Tree/treeTitleVariables'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {
defaultColor: siteVars.colors.white,
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const treeTitleStyles = {
root: ({ variables, theme: { siteVariables } }): ICSSInJSStyle => ({
padding: `${pxToRem(1)} 0`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to variables?

Suggested change
padding: `${pxToRem(1)} 0`,
padding: v.padding,

root: ({ variables, theme: { siteVariables } }): ICSSInJSStyle => ({
padding: `${pxToRem(1)} 0`,
cursor: 'pointer',
color: variables.defaultColor,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
color: variables.defaultColor,
color: v.color,

https://github.com/stardust-ui/react/pull/1779/files#r319038491

import getBorderFocusStyles from '../../getBorderFocusStyles'

const treeTitleStyles = {
root: ({ variables, theme: { siteVariables } }): ICSSInJSStyle => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
root: ({ variables, theme: { siteVariables } }): ICSSInJSStyle => ({
root: ({ variables: v, theme: { siteVariables } }): ICSSInJSStyle => ({

Let's use v.* naming

@@ -0,0 +1,9 @@
export interface TreeTitleVariables {
defaultColor: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defaultColor: string
color: string

https://github.com/stardust-ui/react/pull/1779/files#r319038491

testMethod: (parameters: TestMethod) => {
const [action, key, elementToPerformAction] = [...parameters.props]
const propertyOpenedSubtree = { open: true, items: [{ a: 1 }] }
const propertyOpenedSubtree = { open: true, items: [{ a: 1 }], siblings: [], hasSubtree: true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const propertyOpenedSubtree = { open: true, items: [{ a: 1 }], siblings: [], hasSubtree: true }
const propertyOpenedSubtree = { open: true, hasSubtree: true }

I think that is not required anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still required as it will be used for the Hierarchical tree tests.

import TreeTitle from '../../../../components/Tree/TreeTitle'

const treeItemStyles: ComponentSlotStylesInput<TreeItemProps> = {
root: ({ theme: { siteVariables }, props: { level } }): ICSSInJSStyle => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
root: ({ theme: { siteVariables }, props: { level } }): ICSSInJSStyle => ({
root: ({ theme: { siteVariables }, props: p } }): ICSSInJSStyle => ({

Please use p.* naming

@vercel vercel bot temporarily deployed to staging August 29, 2019 14:24 Inactive
Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on my side, great job!


@miroslavstastny @mnajdova please also take a look

@silviuaavram
Copy link
Collaborator Author

Merging this. We can create issues to follow up, if any.

@silviuaavram silviuaavram merged commit 2d00948 into master Aug 30, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat/flat-tree-component branch August 30, 2019 08:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

⚙️ enhancement New feature or request help wanted Extra attention is needed 🚀 ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants