Skip to content

Commit a02d47e

Browse files
authored
Tags widget (ToolJet#1659)
* implemented tags widget * added text color option, changed default tags * added scrollbar & space between tags * Required changes are added: - Changed colors of buttons as per the document - Now scrollbar only shows if it is needed - Tags height will be static * Changed documentation - Added gif file * Removed text color style option from inspector - Changed md text file
1 parent 3c99dd6 commit a02d47e

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

docs/docs/widgets/tags.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Tags
2+
3+
Tags widget can be used to show array of data as tags.
4+
5+
<img class="screenshot-full" src="/img/widgets/tags/tags.gif" alt="ToolJet - Widget Reference - Tags" height="420"/>
6+
7+
#### Properties
8+
9+
| properties | description |
10+
| ----------- | ----------- |
11+
| Data | It can be used to set array of tags. It must be an array of objects like this ```[ { title: 'tag1', color: '#000000', textColor: '#fff' }, { title: 'tag2', color: '#fefefe', textColor: 'green' } ]```. Each object should contain a title and color code of a particular tag, also a text color.|

docs/static/img/widgets/tags/tags.gif

416 KB
Loading
Lines changed: 1 addition & 0 deletions
Loading

frontend/src/Editor/Box.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Listview } from './Components/Listview';
2929
import { IFrame } from './Components/IFrame';
3030
import { CodeEditor } from './Components/CodeEditor';
3131
import { Timer } from './Components/Timer';
32+
import { Tags } from './Components/Tags';
3233
import { renderTooltip } from '../_helpers/appUtils';
3334
import OverlayTrigger from 'react-bootstrap/OverlayTrigger';
3435
import '@/_styles/custom.scss';
@@ -67,6 +68,7 @@ const AllComponents = {
6768
CodeEditor,
6869
Listview,
6970
Timer,
71+
Tags,
7072
};
7173

7274
export const Box = function Box({
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
3+
export const Tags = function Tags({ width, height, properties, styles }) {
4+
const { data } = properties;
5+
const { visibility } = styles;
6+
7+
const computedStyles = {
8+
width,
9+
height,
10+
display: visibility ? '' : 'none',
11+
overflowY: 'auto',
12+
};
13+
14+
function renderTag(item, index) {
15+
const tagComputedStyles = {
16+
backgroundColor: item.color,
17+
color: item.textColor,
18+
textTransform: 'none',
19+
};
20+
21+
return (
22+
<span className="badge mx-1 mb-1" style={tagComputedStyles} key={index}>
23+
{item.title}
24+
</span>
25+
);
26+
}
27+
28+
return (
29+
<div style={computedStyles}>
30+
{data &&
31+
data.map((item, index) => {
32+
return renderTag(item, index);
33+
})}
34+
</div>
35+
);
36+
};

frontend/src/Editor/Components/components.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,4 +1552,42 @@ export const componentTypes = [
15521552
},
15531553
},
15541554
},
1555+
{
1556+
name: 'Tags',
1557+
displayName: 'Tags',
1558+
description: 'Content can be shown as tags',
1559+
component: 'Tags',
1560+
defaultSize: {
1561+
width: 5,
1562+
height: 30,
1563+
},
1564+
others: {
1565+
showOnDesktop: { type: 'toggle', displayName: 'Show on desktop' },
1566+
showOnMobile: { type: 'toggle', displayName: 'Show on mobile' },
1567+
},
1568+
properties: {
1569+
data: { type: 'code', displayName: 'Tags' },
1570+
},
1571+
events: {},
1572+
styles: {
1573+
visibility: { type: 'code', displayName: 'Visibility' },
1574+
},
1575+
exposedVariables: {},
1576+
definition: {
1577+
others: {
1578+
showOnDesktop: { value: true },
1579+
showOnMobile: { value: false },
1580+
},
1581+
properties: {
1582+
data: {
1583+
value:
1584+
"{{ [ \n\t\t{ title: 'success', color: '#2fb344', textColor: '#fff' }, \n\t\t{ title: 'info', color: '#206bc4', textColor: '#fff' }, \n\t\t{ title: 'warning', color: '#f59f00', textColor: '#fff' }, \n\t\t{ title: 'danger', color: '#d63939', textColor: '#fff' } ] }}",
1585+
},
1586+
},
1587+
events: [],
1588+
styles: {
1589+
visibility: { value: '{{true}}' },
1590+
},
1591+
},
1592+
},
15551593
];

0 commit comments

Comments
 (0)