@platformatic/ui-components 0.1.56 → 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,23 +1,56 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import PlatformaticIcon from './PlatformaticIcon'
|
|
4
4
|
import styles from './ListElement.module.css'
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
function List ({ title, detail, marginSize, titleAspect }) {
|
|
7
|
+
let className = `${styles.container} `
|
|
8
|
+
className += styles[`margin-${marginSize}`]
|
|
9
|
+
|
|
10
|
+
let classNameTitle = `${styles.title} `
|
|
11
|
+
classNameTitle += styles[`${titleAspect}`]
|
|
12
|
+
|
|
6
13
|
return (
|
|
7
|
-
<div className={
|
|
8
|
-
<div className={styles.
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
</div>
|
|
12
|
-
</div>
|
|
13
|
-
<div className={styles.textCol}>
|
|
14
|
-
<div className={styles.title} data-testid='list-element-title'>
|
|
14
|
+
<div className={className}>
|
|
15
|
+
<div className={styles.row}>
|
|
16
|
+
<PlatformaticIcon iconName='CircleCheckMarkIcon' color='green' data-testid='list-element-title-icon' onClick={null} />
|
|
17
|
+
<div className={classNameTitle} data-testid='list-element-title'>
|
|
15
18
|
{title}
|
|
16
19
|
</div>
|
|
17
|
-
<div data-test-id='list-element-detail'>
|
|
18
|
-
{detail}
|
|
19
|
-
</div>
|
|
20
20
|
</div>
|
|
21
|
+
{detail &&
|
|
22
|
+
(
|
|
23
|
+
<div className={styles.textCol} data-test-id='list-element-detail'>
|
|
24
|
+
{detail}
|
|
25
|
+
</div>
|
|
26
|
+
)}
|
|
21
27
|
</div>
|
|
22
28
|
)
|
|
23
29
|
}
|
|
30
|
+
List.propTypes = {
|
|
31
|
+
/**
|
|
32
|
+
* title
|
|
33
|
+
*/
|
|
34
|
+
title: PropTypes.string,
|
|
35
|
+
/**
|
|
36
|
+
* detail
|
|
37
|
+
*/
|
|
38
|
+
detail: PropTypes.string,
|
|
39
|
+
/**
|
|
40
|
+
* marginSize
|
|
41
|
+
*/
|
|
42
|
+
marginSize: PropTypes.oneOf(['small', 'medium']),
|
|
43
|
+
/**
|
|
44
|
+
* titleAspect
|
|
45
|
+
*/
|
|
46
|
+
titleAspect: PropTypes.oneOf(['boldAndGreen', 'lightAndWhite'])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
List.defaultProps = {
|
|
50
|
+
title: '',
|
|
51
|
+
detail: '',
|
|
52
|
+
marginSize: 'medium',
|
|
53
|
+
titleAspect: 'boldAndGreen'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default List
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
.container {
|
|
2
|
-
@apply flex flex-
|
|
2
|
+
@apply flex flex-col my-4
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@apply flex flex-col w-6
|
|
4
|
+
.margin-medium {
|
|
5
|
+
@apply my-4
|
|
7
6
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@apply text-light-green
|
|
7
|
+
.margin-small {
|
|
8
|
+
@apply my-2
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
.title {
|
|
14
|
-
@apply
|
|
11
|
+
@apply w-full;
|
|
12
|
+
}
|
|
13
|
+
.boldAndGreen {
|
|
14
|
+
@apply text-light-green font-bold;
|
|
15
|
+
}
|
|
16
|
+
.lightAndWhite {
|
|
17
|
+
@apply text-white font-light;
|
|
18
|
+
}
|
|
19
|
+
.row {
|
|
20
|
+
@apply flex gap-x-2 items-center w-full;
|
|
15
21
|
}
|
|
16
|
-
|
|
17
22
|
.textCol {
|
|
18
|
-
@apply flex flex-col text-white text-justify w-full
|
|
23
|
+
@apply flex flex-col text-white text-justify w-full ml-6;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
.detailSpace {
|
|
@@ -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: () => {},
|
|
@@ -15,7 +15,7 @@ ListWithNoElements.args = {
|
|
|
15
15
|
|
|
16
16
|
const TemplateWithElements = (args) => (
|
|
17
17
|
<List {...args}>
|
|
18
|
-
<ListElement title='List Element 1' detail='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et dui facilisis, molestie urna sed, volutpat nibh.' />
|
|
18
|
+
<ListElement title='List Element 1' detail='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et dui facilisis, molestie urna sed, volutpat nibh.' titleAspect='boldAndGreen' />
|
|
19
19
|
<ListElement title='List Element 2' detail='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et dui facilisis, molestie urna sed, volutpat nibh.' />
|
|
20
20
|
</List>
|
|
21
21
|
)
|
|
@@ -27,3 +27,15 @@ ListWithElements.args = {
|
|
|
27
27
|
|
|
28
28
|
export const ListWithElementsNoTitle = TemplateWithElements.bind({})
|
|
29
29
|
ListWithElementsNoTitle.args = {}
|
|
30
|
+
|
|
31
|
+
const TemplateWithElementsVariants = (args) => (
|
|
32
|
+
<List {...args}>
|
|
33
|
+
<ListElement title='List Element 1' titleAspect='boldAndGreen' marginSize='small' />
|
|
34
|
+
<ListElement title='List Element 2' titleAspect='lightAndWhite' marginSize='small' />
|
|
35
|
+
</List>
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
export const ListWithElementsVariants = TemplateWithElementsVariants.bind({})
|
|
39
|
+
ListWithElementsVariants.args = {
|
|
40
|
+
title: 'List Title'
|
|
41
|
+
}
|
|
@@ -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
|
+
}
|