- Notifications
You must be signed in to change notification settings - Fork254
Tags component#1818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
kamalqureshi wants to merge5 commits intolowcoder-org:devChoose a base branch fromkamalqureshi:tags_component
base:dev
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Tags component#1818
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletionsclient/packages/lowcoder-design/src/icons/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletionsclient/packages/lowcoder-design/src/icons/v2/tags-l.svg
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletionsclient/packages/lowcoder-design/src/icons/v2/tags-s.svg
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletionclient/packages/lowcoder/src/comps/comps/selectInputComp/multiSelectComp.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionclient/packages/lowcoder/src/comps/comps/selectInputComp/selectComp.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletionsclient/packages/lowcoder/src/comps/comps/tagsComp/tagsCompView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { | ||
BoolCodeControl, | ||
ButtonEventHandlerControl, | ||
InputLikeStyle, | ||
NameConfig, | ||
Section, | ||
UICompBuilder, | ||
hiddenPropertyView, | ||
sectionNames, | ||
showDataLoadingIndicatorsPropertyView, | ||
styleControl, | ||
withExposingConfigs | ||
} from "@lowcoder-ee/index.sdk"; | ||
import styled from "styled-components"; | ||
import React, { useContext } from "react"; | ||
import { trans } from "i18n"; | ||
import { Tag } from "antd"; | ||
import { EditorContext } from "comps/editorState"; | ||
import { PresetStatusColorTypes } from "antd/es/_util/colors"; | ||
import { hashToNum } from "util/stringUtils"; | ||
import { TagsCompOptionsControl } from "comps/controls/optionsControl"; | ||
import { useCompClickEventHandler } from "@lowcoder-ee/comps/utils/useCompClickEventHandler"; | ||
const colors = PresetStatusColorTypes; | ||
// These functions are used for individual tag styling | ||
function getTagColor(tagText : any, tagOptions: any[]) { | ||
const foundOption = tagOptions.find((option: { label: any; }) => option.label === tagText); | ||
if (foundOption) { | ||
if (foundOption.colorType === "preset") { | ||
return foundOption.presetColor; | ||
} else if (foundOption.colorType === "custom") { | ||
return undefined; | ||
} | ||
return foundOption.color; | ||
} | ||
const index = Math.abs(hashToNum(tagText)) % colors.length; | ||
return colors[index]; | ||
} | ||
const getTagStyle = (tagText: any, tagOptions: any[], baseStyle: any = {}) => { | ||
const foundOption = tagOptions.find((option: { label: any; }) => option.label === tagText); | ||
if (foundOption) { | ||
const style: any = { ...baseStyle }; | ||
if (foundOption.colorType === "custom") { | ||
style.backgroundColor = foundOption.color; | ||
style.color = foundOption.textColor; | ||
style.border = `1px solid ${foundOption.color}`; | ||
} | ||
if (foundOption.border) { | ||
style.borderColor = foundOption.border; | ||
if (!foundOption.colorType || foundOption.colorType !== "custom") { | ||
style.border = `1px solid ${foundOption.border}`; | ||
} | ||
} | ||
if (foundOption.radius) { | ||
style.borderRadius = foundOption.radius; | ||
} | ||
if (foundOption.margin) { | ||
style.margin = foundOption.margin; | ||
} | ||
if (foundOption.padding) { | ||
style.padding = foundOption.padding; | ||
} | ||
return style; | ||
} | ||
return baseStyle; | ||
}; | ||
function getTagIcon(tagText: any, tagOptions: any[]) { | ||
const foundOption = tagOptions.find(option => option.label === tagText); | ||
return foundOption ? foundOption.icon : undefined; | ||
} | ||
const multiTags = (function () { | ||
const StyledTag = styled(Tag)<{ $style: any, $bordered: boolean, $customStyle: any }>` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 100%; | ||
background: ${(props) => props.$customStyle?.backgroundColor || props.$style?.background}; | ||
color: ${(props) => props.$customStyle?.color || props.$style?.text}; | ||
border-radius: ${(props) => props.$customStyle?.borderRadius || props.$style?.borderRadius}; | ||
border: ${(props) => { | ||
if (props.$customStyle?.border) return props.$customStyle.border; | ||
return props.$bordered ? `${props.$style?.borderStyle} ${props.$style?.borderWidth} ${props.$style?.border}` : 'none'; | ||
}}; | ||
padding: ${(props) => props.$customStyle?.padding || props.$style?.padding}; | ||
margin: ${(props) => props.$customStyle?.margin || props.$style?.margin}; | ||
font-size: ${(props) => props.$style?.textSize}; | ||
font-weight: ${(props) => props.$style?.fontWeight}; | ||
cursor: pointer; | ||
`; | ||
const StyledTagContainer = styled.div` | ||
display: flex; | ||
gap: 5px; | ||
padding: 5px; | ||
`; | ||
const childrenMap = { | ||
options: TagsCompOptionsControl, | ||
style: styleControl(InputLikeStyle, 'style'), | ||
onEvent: ButtonEventHandlerControl, | ||
borderless: BoolCodeControl, | ||
enableIndividualStyling: BoolCodeControl, | ||
}; | ||
return new UICompBuilder(childrenMap, (props) => { | ||
const handleClickEvent = useCompClickEventHandler({onEvent: props.onEvent}); | ||
return ( | ||
<StyledTagContainer> | ||
{props.options.map((tag, index) => { | ||
// Use individual styling only if enableIndividualStyling is true | ||
const tagColor = props.enableIndividualStyling ? getTagColor(tag.label, props.options) : undefined; | ||
const tagIcon = props.enableIndividualStyling ? getTagIcon(tag.label, props.options) : tag.icon; | ||
const tagStyle = props.enableIndividualStyling ? getTagStyle(tag.label, props.options, props.style) : {}; | ||
return ( | ||
<StyledTag | ||
key={`tag-${index}`} | ||
$style={props.style} | ||
$bordered={!props.borderless} | ||
$customStyle={tagStyle} | ||
icon={tagIcon} | ||
color={tagColor} | ||
onClick={() => handleClickEvent()} | ||
> | ||
{tag.label} | ||
</StyledTag> | ||
); | ||
})} | ||
</StyledTagContainer> | ||
); | ||
}) | ||
.setPropertyViewFn((children: any) => { | ||
return ( | ||
<> | ||
<Section name="Basic"> | ||
{children.options.propertyView({})} | ||
</Section> | ||
{["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( | ||
<Section name={sectionNames.interaction}> | ||
{children.onEvent.getPropertyView()} | ||
{hiddenPropertyView(children)} | ||
{showDataLoadingIndicatorsPropertyView(children)} | ||
</Section> | ||
)} | ||
{["layout", "both"].includes( | ||
useContext(EditorContext).editorModeStatus | ||
) && ( | ||
<Section name={sectionNames.style}> | ||
{children.enableIndividualStyling.propertyView({ | ||
label: trans("style.individualStyling"), | ||
tooltip: trans("style.individualStylingTooltip") | ||
})} | ||
{children.borderless.propertyView({ label: trans("style.borderless") })} | ||
{children.style.getPropertyView()} | ||
</Section> | ||
)} | ||
</> | ||
) | ||
}) | ||
.build(); | ||
})() | ||
export const MultiTagsComp = withExposingConfigs(multiTags, [new NameConfig("options", "")]); | ||
111 changes: 106 additions & 5 deletionsclient/packages/lowcoder/src/comps/controls/optionsControl.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.