Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
design-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASTRON SDC
design-system
Commits
647555cd
Commit
647555cd
authored
1 year ago
by
Alissa Cheng
Browse files
Options
Downloads
Patches
Plain Diff
fix: icons in table stories
parent
469db3a6
No related branches found
No related tags found
1 merge request
!43
Empty states (table)
Pipeline
#77519
passed
1 year ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/stories/Table.stories.tsx
+94
-41
94 additions, 41 deletions
src/stories/Table.stories.tsx
with
94 additions
and
41 deletions
src/stories/Table.stories.tsx
+
94
−
41
View file @
647555cd
...
@@ -63,7 +63,7 @@ const rows = [
...
@@ -63,7 +63,7 @@ const rows = [
name
:
"
Tony
"
,
name
:
"
Tony
"
,
role
:
"
CEO
"
,
role
:
"
CEO
"
,
status
:
<
Badge
text
=
"Active"
/>,
status
:
<
Badge
text
=
"Active"
/>,
action
:
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
e
dit"
/>,
action
:
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
E
dit"
/>,
},
},
{
{
key
:
"
2
"
,
key
:
"
2
"
,
...
@@ -72,8 +72,8 @@ const rows = [
...
@@ -72,8 +72,8 @@ const rows = [
status
:
<
Badge
text
=
"Paused"
color
=
"warning"
/>,
status
:
<
Badge
text
=
"Paused"
color
=
"warning"
/>,
action
:
(
action
:
(
<
div
className
=
"flex flex-row gap-3 w-fit"
>
<
div
className
=
"flex flex-row gap-3 w-fit"
>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
e
dit"
/>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
E
dit"
/>
<
Button
label
=
"Delete"
color
=
"negative"
icon
=
"
c
ross"
/>
<
Button
label
=
"Delete"
color
=
"negative"
icon
=
"
C
ross"
/>
</
div
>
</
div
>
),
),
},
},
...
@@ -84,8 +84,8 @@ const rows = [
...
@@ -84,8 +84,8 @@ const rows = [
status
:
<
Badge
text
=
"Inactive"
color
=
"negative"
/>,
status
:
<
Badge
text
=
"Inactive"
color
=
"negative"
/>,
action
:
(
action
:
(
<
div
className
=
"flex flex-row gap-3"
>
<
div
className
=
"flex flex-row gap-3"
>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
e
dit"
/>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
E
dit"
/>
<
Button
label
=
"Delete"
color
=
"negative"
icon
=
"
c
ross"
/>
<
Button
label
=
"Delete"
color
=
"negative"
icon
=
"
C
ross"
/>
</
div
>
</
div
>
),
),
},
},
...
@@ -96,8 +96,8 @@ const rows = [
...
@@ -96,8 +96,8 @@ const rows = [
status
:
<
Badge
text
=
"Vacation"
color
=
"neutral"
/>,
status
:
<
Badge
text
=
"Vacation"
color
=
"neutral"
/>,
action
:
(
action
:
(
<
div
className
=
"flex flex-row gap-3"
>
<
div
className
=
"flex flex-row gap-3"
>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
e
dit"
/>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
E
dit"
/>
<
Button
label
=
"View"
color
=
"primary"
icon
=
"
e
ye"
/>
<
Button
label
=
"View"
color
=
"primary"
icon
=
"
E
ye"
/>
</
div
>
</
div
>
),
),
},
},
...
@@ -110,14 +110,21 @@ export const TableWithText: StoryObj = {
...
@@ -110,14 +110,21 @@ export const TableWithText: StoryObj = {
},
},
};
};
export
const
EmptyTable
:
StoryObj
=
{
args
:
{
columns
:
textColumns
,
rows
:
[],
},
};
export
const
TableWithComponentsInHeader
:
StoryObj
=
{
export
const
TableWithComponentsInHeader
:
StoryObj
=
{
args
:
{
args
:
{
columns
:
textColumns
,
columns
:
textColumns
,
rows
:
textRows
,
rows
:
textRows
,
headerContent
:
(
headerContent
:
(
<
div
className
=
"flex flex-row gap-2 pb-[10px]"
>
<
div
className
=
"flex flex-row gap-2 pb-[10px]"
>
<
Button
label
=
"Create New"
color
=
"positive"
icon
=
"
p
lus"
/>
<
Button
label
=
"Create New"
color
=
"positive"
icon
=
"
P
lus"
/>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
e
dit"
/>
<
Button
label
=
"Edit"
color
=
"secondary"
icon
=
"
E
dit"
/>
</
div
>
</
div
>
),
),
},
},
...
@@ -175,8 +182,6 @@ export const TableWithReorderableRows = () => {
...
@@ -175,8 +182,6 @@ export const TableWithReorderableRows = () => {
);
);
};
};
type
Row
=
{
type
Row
=
{
row_id
:
string
;
row_id
:
string
;
name
:
string
;
name
:
string
;
...
@@ -184,8 +189,7 @@ type Row = {
...
@@ -184,8 +189,7 @@ type Row = {
salary
:
number
;
salary
:
number
;
notes
:
string
;
notes
:
string
;
action
:
JSX
.
Element
;
action
:
JSX
.
Element
;
}
};
const
editableColumnRows
=
[
const
editableColumnRows
=
[
{
{
...
@@ -208,24 +212,38 @@ const editableColumnRows = [
...
@@ -208,24 +212,38 @@ const editableColumnRows = [
role
:
"
Project manager
"
,
role
:
"
Project manager
"
,
salary
:
2000000
,
salary
:
2000000
,
notes
:
"
Micro manager
"
,
notes
:
"
Micro manager
"
,
}
}
,
]
as
Row
[];
]
as
Row
[];
/** Cells can be edited, cell values can be validated */
/** Cells can be edited, cell values can be validated */
export
const
TableWithEditableCells
=
()
=>
{
export
const
TableWithEditableCells
=
()
=>
{
const
textEditor
=
(
options
:
ColumnEditorOptions
)
=>
{
const
textEditor
=
(
options
:
ColumnEditorOptions
)
=>
{
return
<
TextInput
value
=
{
options
.
value
as
string
}
onValueChange
=
{
(
e
)
=>
options
.
editorCallback
&&
options
.
editorCallback
(
e
)
}
></
TextInput
>
return
(
<
TextInput
value
=
{
options
.
value
as
string
}
onValueChange
=
{
(
e
)
=>
options
.
editorCallback
&&
options
.
editorCallback
(
e
)
}
></
TextInput
>
);
};
};
const
numberEditor
=
(
options
:
ColumnEditorOptions
)
=>
{
const
numberEditor
=
(
options
:
ColumnEditorOptions
)
=>
{
return
<
TextInput
type
=
"number"
value
=
{
options
.
value
as
string
}
onValueChange
=
{
(
e
)
=>
options
.
editorCallback
&&
options
.
editorCallback
(
e
)
}
></
TextInput
>
return
(
<
TextInput
type
=
"number"
value
=
{
options
.
value
as
string
}
onValueChange
=
{
(
e
)
=>
options
.
editorCallback
&&
options
.
editorCallback
(
e
)
}
></
TextInput
>
);
};
};
const
onCellEditComplete
=
(
e
:
ColumnEvent
)
=>
{
const
onCellEditComplete
=
(
e
:
ColumnEvent
)
=>
{
const
{
rowData
,
newValue
,
field
}
=
e
;
const
{
rowData
,
newValue
,
field
}
=
e
;
rowData
[
field
]
=
newValue
;
rowData
[
field
]
=
newValue
;
}
}
;
const
isPositiveInteger
=
(
val
:
unknown
)
=>
{
const
isPositiveInteger
=
(
val
:
unknown
)
=>
{
let
str
=
String
(
val
);
let
str
=
String
(
val
);
...
@@ -236,7 +254,7 @@ export const TableWithEditableCells = () => {
...
@@ -236,7 +254,7 @@ export const TableWithEditableCells = () => {
return
false
;
return
false
;
}
}
str
=
str
.
replace
(
/^0+/
,
''
)
||
'
0
'
;
str
=
str
.
replace
(
/^0+/
,
""
)
||
"
0
"
;
const
n
=
Math
.
floor
(
Number
(
str
));
const
n
=
Math
.
floor
(
Number
(
str
));
return
n
!==
Infinity
&&
String
(
n
)
===
str
&&
n
>=
0
;
return
n
!==
Infinity
&&
String
(
n
)
===
str
&&
n
>=
0
;
...
@@ -249,13 +267,25 @@ export const TableWithEditableCells = () => {
...
@@ -249,13 +267,25 @@ export const TableWithEditableCells = () => {
}
else
{
}
else
{
event
.
preventDefault
();
event
.
preventDefault
();
}
}
}
}
;
const
editableColumns
=
[
const
editableColumns
=
[
{
field
:
"
row_id
"
,
header
:
"
ID
"
,
style
:
{
width
:
"
30%
"
}
},
{
field
:
"
row_id
"
,
header
:
"
ID
"
,
style
:
{
width
:
"
30%
"
}
},
{
field
:
"
name
"
,
header
:
"
Name
"
,
style
:
{
width
:
"
20%
"
},
editor
:
textEditor
,
onCellEditComplete
:
onCellEditComplete
},
{
field
:
"
name
"
,
header
:
"
Name
"
,
style
:
{
width
:
"
20%
"
},
editor
:
textEditor
,
onCellEditComplete
:
onCellEditComplete
,
},
{
field
:
"
role
"
,
header
:
"
Role
"
,
style
:
{
width
:
"
20%
"
}
},
{
field
:
"
role
"
,
header
:
"
Role
"
,
style
:
{
width
:
"
20%
"
}
},
{
field
:
"
salary
"
,
header
:
"
Salary
"
,
style
:
{
width
:
"
10%
"
},
editor
:
numberEditor
,
onCellEditComplete
:
onSalaryEditComplete
},
{
field
:
"
salary
"
,
header
:
"
Salary
"
,
style
:
{
width
:
"
10%
"
},
editor
:
numberEditor
,
onCellEditComplete
:
onSalaryEditComplete
,
},
{
field
:
"
notes
"
,
header
:
"
Notes
"
,
style
:
{
width
:
"
10%
"
}
},
{
field
:
"
notes
"
,
header
:
"
Notes
"
,
style
:
{
width
:
"
10%
"
}
},
{
field
:
"
action
"
,
header
:
""
,
style
:
{
width
:
"
10%
"
}
},
{
field
:
"
action
"
,
header
:
""
,
style
:
{
width
:
"
10%
"
}
},
];
];
...
@@ -263,29 +293,52 @@ export const TableWithEditableCells = () => {
...
@@ -263,29 +293,52 @@ export const TableWithEditableCells = () => {
const
[
editableRows
,
setEditableRows
]
=
useState
<
Row
[]
>
([]);
const
[
editableRows
,
setEditableRows
]
=
useState
<
Row
[]
>
([]);
useEffect
(()
=>
{
useEffect
(()
=>
{
setEditableRows
(
editableColumnRows
)
setEditableRows
(
editableColumnRows
)
;
},
[]);
},
[]);
const
deleteButton
=
(
row
:
Row
)
=>
<
Button
label
=
{
"
Delete
"
}
icon
=
{
"
cross
"
}
onClick
=
{
()
=>
{
deleteEmployee
(
row
)
}
}
/>
const
deleteButton
=
(
row
:
Row
)
=>
(
<
Button
label
=
"Delete"
icon
=
"Cross"
onClick
=
{
()
=>
{
deleteEmployee
(
row
);
}
}
/>
);
for
(
const
row
of
editableRows
)
{
for
(
const
row
of
editableRows
)
{
row
.
action
=
deleteButton
(
row
);
row
.
action
=
deleteButton
(
row
);
}
}
const
addEmployee
=
()
=>
{
const
addEmployee
=
()
=>
{
const
newRow
=
{
row_id
:
crypto
.
randomUUID
(),
name
:
""
,
role
:
""
,
salary
:
0
,
notes
:
""
}
as
Row
;
const
newRow
=
{
row_id
:
crypto
.
randomUUID
(),
name
:
""
,
role
:
""
,
salary
:
0
,
notes
:
""
,
}
as
Row
;
newRow
.
action
=
deleteButton
(
newRow
);
newRow
.
action
=
deleteButton
(
newRow
);
setEditableRows
(
old
=>
[...
old
,
newRow
])
setEditableRows
(
(
old
)
=>
[...
old
,
newRow
])
;
};
};
const
deleteEmployee
=
(
row
:
Row
)
=>
{
const
deleteEmployee
=
(
row
:
Row
)
=>
{
const
newRows
=
editableRows
.
filter
(
r
=>
r
!==
row
);
const
newRows
=
editableRows
.
filter
(
(
r
)
=>
r
!==
row
);
setEditableRows
(
newRows
);
setEditableRows
(
newRows
);
};
};
return
(
return
(
<
Table
<
Table
headerContent
=
{
<
div
className
=
"flex flex-row gap-2 pb-[10px]"
><
Button
color
=
"positive"
icon
=
"plus"
label
=
"Add Employee"
onClick
=
{
addEmployee
}
/></
div
>
}
headerContent
=
{
<
div
className
=
"flex flex-row gap-2 pb-[10px]"
>
<
Button
color
=
"positive"
icon
=
"Plus"
label
=
"Add Employee"
onClick
=
{
addEmployee
}
/>
</
div
>
}
columns
=
{
editableColumns
}
columns
=
{
editableColumns
}
rows
=
{
editableRows
}
rows
=
{
editableRows
}
editMode
=
"cell"
editMode
=
"cell"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment