@platformatic/ui-components 0.1.57 → 0.1.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
2
|
import Icons from './icons'
|
|
3
3
|
import styles from './Sidebar.module.css'
|
|
4
4
|
import ReactTooltip from 'react-tooltip'
|
|
@@ -17,13 +17,17 @@ function Sidebar (props) {
|
|
|
17
17
|
onClickSettings
|
|
18
18
|
} = props
|
|
19
19
|
const [collapsed, setCollapsed] = useState(false)
|
|
20
|
-
const [selectedItem, setSelectedItem] = useState(
|
|
20
|
+
const [selectedItem, setSelectedItem] = useState(null)
|
|
21
21
|
|
|
22
|
-
function onClickItemSelected (
|
|
23
|
-
setSelectedItem(
|
|
24
|
-
onClickItemSelectedParent(
|
|
22
|
+
function onClickItemSelected (item) {
|
|
23
|
+
setSelectedItem(item.id)
|
|
24
|
+
onClickItemSelectedParent(item.id)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setSelectedItem(defaultSelected)
|
|
29
|
+
}, [defaultSelected])
|
|
30
|
+
|
|
27
31
|
return (
|
|
28
32
|
<div className={`${styles.container} ${collapsed && styles.collapsed}`}>
|
|
29
33
|
{collapsed
|
|
@@ -63,11 +67,11 @@ function Sidebar (props) {
|
|
|
63
67
|
{title}
|
|
64
68
|
</div>
|
|
65
69
|
<div className={styles.items} data-test-id='lateral-bar-items'>
|
|
66
|
-
{items.map(
|
|
67
|
-
const isSelected = selectedItem ===
|
|
70
|
+
{items.map(item => {
|
|
71
|
+
const isSelected = selectedItem === item.id
|
|
68
72
|
return (
|
|
69
|
-
<React.Fragment key={
|
|
70
|
-
<button className={`${styles.buttonItem} ${collapsed && styles.buttonItemCollapsed}`} type='button' onClick={() => onClickItemSelected(
|
|
73
|
+
<React.Fragment key={item.id}>
|
|
74
|
+
<button className={`${styles.buttonItem} ${collapsed && styles.buttonItemCollapsed}`} type='button' onClick={() => onClickItemSelected(item)}>
|
|
71
75
|
{item.iconName && (<PlatformaticIcon
|
|
72
76
|
iconName={item.iconName}
|
|
73
77
|
color={isSelected ? 'green' : 'white'}
|
|
@@ -114,18 +118,20 @@ Sidebar.propTypes = {
|
|
|
114
118
|
/**
|
|
115
119
|
* defaultSelected
|
|
116
120
|
*/
|
|
117
|
-
defaultSelected: PropTypes.
|
|
121
|
+
defaultSelected: PropTypes.string,
|
|
118
122
|
/**
|
|
119
123
|
* addTitle
|
|
120
124
|
*/
|
|
121
125
|
addTitle: PropTypes.string,
|
|
122
126
|
/**
|
|
123
127
|
* items: array with keys
|
|
128
|
+
* id: id of the worspacedSeleted
|
|
124
129
|
* title: name to display
|
|
125
130
|
* subtitle: secondary title
|
|
126
131
|
* icon: what Icon
|
|
127
132
|
*/
|
|
128
133
|
items: PropTypes.arrayOf(PropTypes.shape({
|
|
134
|
+
id: PropTypes.string.isRequired,
|
|
129
135
|
title: PropTypes.string,
|
|
130
136
|
subtitle: PropTypes.string,
|
|
131
137
|
iconName: PropTypes.string
|
|
@@ -147,7 +153,7 @@ Sidebar.propTypes = {
|
|
|
147
153
|
|
|
148
154
|
Sidebar.defaultProps = {
|
|
149
155
|
title: '',
|
|
150
|
-
defaultSelected:
|
|
156
|
+
defaultSelected: null,
|
|
151
157
|
onClickItemSelectedParent: () => {},
|
|
152
158
|
items: [],
|
|
153
159
|
onClickAdd: () => {},
|
|
@@ -36,9 +36,9 @@ EmptySidebar.args = {
|
|
|
36
36
|
|
|
37
37
|
const FullSidebarTemplate = (args) => {
|
|
38
38
|
const [items, setItems] = useState([
|
|
39
|
-
{ iconName: 'WorkspaceStaticIcon', subTitle: 'Subtitle', title: 'a very very very very very long title 1' },
|
|
40
|
-
{ title: 'Title number 2', subTitle: 'Subtitle 2' },
|
|
41
|
-
{ title: 'Another Title', subTitle: 'Subtitle 3', iconName: 'WorkspaceDynamicIcon' }
|
|
39
|
+
{ id: '1', iconName: 'WorkspaceStaticIcon', subTitle: 'Subtitle', title: 'a very very very very very long title 1' },
|
|
40
|
+
{ id: '2', title: 'Title number 2', subTitle: 'Subtitle 2' },
|
|
41
|
+
{ id: '3', title: 'Another Title', subTitle: 'Subtitle 3', iconName: 'WorkspaceDynamicIcon' }
|
|
42
42
|
])
|
|
43
43
|
function onClickAdd () {
|
|
44
44
|
const tmpItem = items.map(item => item)
|
|
@@ -59,3 +59,18 @@ FullSidebar.args = {
|
|
|
59
59
|
onClickItemSelected: (index) => alert('selected: ' + index),
|
|
60
60
|
onClickSettings: () => alert('settings')
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
export const AlreadySelected = Template.bind({})
|
|
64
|
+
|
|
65
|
+
AlreadySelected.args = {
|
|
66
|
+
title: 'Sidebar bar Full',
|
|
67
|
+
addTitle: 'Create',
|
|
68
|
+
defaultSelected: '3',
|
|
69
|
+
items: [
|
|
70
|
+
{ id: '1', iconName: 'WorkspaceStaticIcon', title: 'Static 1', subTitle: 'Subtitle 1' },
|
|
71
|
+
{ id: '2', iconName: 'WorkspaceStaticIcon', title: 'Static 2', subTitle: 'Subtitle 2' },
|
|
72
|
+
{ id: '3', iconName: 'WorkspaceDynamicIcon', title: 'Dynamic', subTitle: 'Subtitle 3' }
|
|
73
|
+
],
|
|
74
|
+
onClickItemSelected: (index) => alert('selected: ' + index),
|
|
75
|
+
onClickSettings: () => alert('settings')
|
|
76
|
+
}
|