Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
c9157c28
Commit
c9157c28
authored
Jun 11, 2024
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag group select component
parent
f5500773
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
0 deletions
+95
-0
Tag.ts
theme/components/Tag/Tag.ts
+18
-0
TagGroupSelect.pw.tsx
ui/shared/tagGroupSelect/TagGroupSelect.pw.tsx
+22
-0
TagGroupSelect.tsx
ui/shared/tagGroupSelect/TagGroupSelect.tsx
+55
-0
TagGroupSelect.pw.tsx_dark-color-mode_base-view-dark-mode-1.png
...upSelect.pw.tsx_dark-color-mode_base-view-dark-mode-1.png
+0
-0
TagGroupSelect.pw.tsx_default_base-view-dark-mode-1.png
..._/TagGroupSelect.pw.tsx_default_base-view-dark-mode-1.png
+0
-0
No files found.
theme/components/Tag/Tag.ts
View file @
c9157c28
...
@@ -3,9 +3,11 @@ import {
...
@@ -3,9 +3,11 @@ import {
createMultiStyleConfigHelpers
,
createMultiStyleConfigHelpers
,
defineStyle
,
defineStyle
,
}
from
'
@chakra-ui/styled-system
'
;
}
from
'
@chakra-ui/styled-system
'
;
import
{
mode
}
from
'
@chakra-ui/theme-tools
'
;
import
getDefaultTransitionProps
from
'
../../utils/getDefaultTransitionProps
'
;
import
getDefaultTransitionProps
from
'
../../utils/getDefaultTransitionProps
'
;
import
Badge
from
'
../Badge
'
;
import
Badge
from
'
../Badge
'
;
const
transitionProps
=
getDefaultTransitionProps
();
const
transitionProps
=
getDefaultTransitionProps
();
const
{
defineMultiStyleConfig
,
definePartsStyle
}
=
const
{
defineMultiStyleConfig
,
definePartsStyle
}
=
...
@@ -15,6 +17,22 @@ const variants = {
...
@@ -15,6 +17,22 @@ const variants = {
subtle
:
definePartsStyle
((
props
)
=>
({
subtle
:
definePartsStyle
((
props
)
=>
({
container
:
Badge
.
variants
?.
subtle
(
props
),
container
:
Badge
.
variants
?.
subtle
(
props
),
})),
})),
select
:
definePartsStyle
((
props
)
=>
({
container
:
{
bg
:
mode
(
'
gray.100
'
,
'
gray.800
'
)(
props
),
color
:
mode
(
'
gray.500
'
,
'
whiteAlpha.800
'
)(
props
),
_hover
:
{
color
:
'
blue.400
'
,
opacity
:
0.76
,
},
},
})),
selectActive
:
definePartsStyle
((
props
)
=>
({
container
:
{
bg
:
mode
(
'
blue.500
'
,
'
blue.900
'
)(
props
),
color
:
'
whiteAlpha.800
'
,
},
})),
};
};
const
sizes
=
{
const
sizes
=
{
...
...
ui/shared/tagGroupSelect/TagGroupSelect.pw.tsx
0 → 100644
View file @
c9157c28
import
_noop
from
'
lodash/noop
'
;
import
React
from
'
react
'
;
import
{
test
,
expect
}
from
'
playwright/lib
'
;
import
TagGroupSelect
from
'
./TagGroupSelect
'
;
test
.
use
({
viewport
:
{
width
:
480
,
height
:
140
}
});
test
(
'
base view +@dark-mode
'
,
async
({
render
})
=>
{
const
component
=
await
render
(
<
TagGroupSelect
items=
{
[
{
id
:
'
1
'
,
title
:
'
Option 1
'
},
{
id
:
'
2
'
,
title
:
'
Option 2
'
},
{
id
:
'
duck
'
,
title
:
'
Cute little duck
'
}
]
}
value=
"duck"
onChange=
{
_noop
}
/>,
);
await
component
.
getByText
(
'
Option 2
'
).
hover
();
await
expect
(
component
).
toHaveScreenshot
();
});
ui/shared/tagGroupSelect/TagGroupSelect.tsx
0 → 100644
View file @
c9157c28
import
{
HStack
,
Tag
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
type
Props
<
T
extends
string
>
=
{
items
:
Array
<
{
id
:
T
;
title
:
string
}
>
;
}
&
(
{
value
:
T
;
onChange
:
(
value
:
T
)
=>
void
;
isMulti
?:
false
;
}
|
{
value
:
Array
<
T
>
;
onChange
:
(
value
:
Array
<
T
>
)
=>
void
;
isMulti
:
true
;
}
)
const
TagGroupSelect
=
<
T
extends
string
>
(
{
items
,
value
,
isMulti
,
onChange
}
: Props
<
T
>
) =
>
{
const
onItemClick
=
React
.
useCallback
((
event
:
React
.
SyntheticEvent
)
=>
{
const
itemValue
=
(
event
.
currentTarget
as
HTMLDivElement
).
getAttribute
(
'
data-id
'
)
as
T
;
if
(
isMulti
)
{
let
newValue
;
if
(
value
.
includes
(
itemValue
))
{
newValue
=
value
.
filter
(
i
=>
i
!==
itemValue
);
}
else
{
newValue
=
[
...
value
,
itemValue
];
}
onChange
(
newValue
);
}
else
{
onChange
(
itemValue
);
}
},
[
isMulti
,
onChange
,
value
]);
return
(
<
HStack
>
{
items
.
map
(
item
=>
{
const
isActive
=
isMulti
?
value
.
includes
(
item
.
id
)
:
value
===
item
.
id
;
return
(
<
Tag
key=
{
item
.
id
}
data
-
id=
{
item
.
id
}
variant=
{
isActive
?
'
selectActive
'
:
'
select
'
}
fontWeight=
{
500
}
cursor=
"pointer"
onClick=
{
onItemClick
}
>
{
item
.
title
}
</
Tag
>
);
})
}
</
HStack
>
);
}
;
export default TagGroupSelect;
ui/shared/tagGroupSelect/__screenshots__/TagGroupSelect.pw.tsx_dark-color-mode_base-view-dark-mode-1.png
0 → 100644
View file @
c9157c28
3.91 KB
ui/shared/tagGroupSelect/__screenshots__/TagGroupSelect.pw.tsx_default_base-view-dark-mode-1.png
0 → 100644
View file @
c9157c28
3.72 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment