-
Notifications
You must be signed in to change notification settings - Fork 245
Icons expansion #338
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
FalkWolsky
merged 5 commits into
lowcoder-org:remix-icons
from
mousheng:Icons-Expansion
Feb 20, 2024
Merged
Icons expansion #338
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5919277
图标选择组件添加antD图标
mousheng f3cb674
add_icon_component
mousheng fd9c3cc
fix_toggle_button_icon_bug
mousheng 05dec1e
Merge branch 'main' into Icons-Expansion
FalkWolsky 98d5c05
Merge branch 'remix-icons' into Icons-Expansion
FalkWolsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,142 @@ | ||
import { useEffect, useRef, useState } from "react"; | ||
import styled, { css } from "styled-components"; | ||
import { RecordConstructorToView } from "lowcoder-core"; | ||
import { styleControl } from "comps/controls/styleControl"; | ||
import _ from "lodash"; | ||
import { | ||
IconStyle, | ||
IconStyleType, | ||
heightCalculator, | ||
widthCalculator, | ||
} from "comps/controls/styleControlConstants"; | ||
import { UICompBuilder } from "comps/generators/uiCompBuilder"; | ||
import { withDefault } from "../generators"; | ||
import { | ||
NameConfigHidden, | ||
withExposingConfigs, | ||
} from "comps/generators/withExposing"; | ||
import { Section, sectionNames } from "lowcoder-design"; | ||
import { hiddenPropertyView } from "comps/utils/propertyUtils"; | ||
import { trans } from "i18n"; | ||
import { NumberControl } from "comps/controls/codeControl"; | ||
import { IconControl } from "comps/controls/iconControl"; | ||
import ReactResizeDetector from "react-resize-detector"; | ||
import { AutoHeightControl } from "../controls/autoHeightControl"; | ||
import { | ||
clickEvent, | ||
eventHandlerControl, | ||
} from "../controls/eventHandlerControl"; | ||
|
||
const Container = styled.div<{ $style: IconStyleType | undefined }>` | ||
height: 100%; | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
svg { | ||
object-fit: contain; | ||
pointer-events: auto; | ||
} | ||
${(props) => props.$style && getStyle(props.$style)} | ||
`; | ||
|
||
const getStyle = (style: IconStyleType) => { | ||
return css` | ||
svg { | ||
color: ${style.fill}; | ||
} | ||
padding: ${style.padding}; | ||
border: 1px solid ${style.border}; | ||
border-radius: ${style.radius}; | ||
margin: ${style.margin}; | ||
max-width: ${widthCalculator(style.margin)}; | ||
max-height: ${heightCalculator(style.margin)}; | ||
`; | ||
}; | ||
|
||
const EventOptions = [clickEvent] as const; | ||
|
||
const childrenMap = { | ||
style: styleControl(IconStyle), | ||
icon: withDefault(IconControl, "/icon:antd/homefilled"), | ||
autoHeight: withDefault(AutoHeightControl, "auto"), | ||
iconSize: withDefault(NumberControl, 20), | ||
onEvent: eventHandlerControl(EventOptions), | ||
}; | ||
|
||
const IconView = (props: RecordConstructorToView<typeof childrenMap>) => { | ||
const conRef = useRef<HTMLDivElement>(null); | ||
const [width, setWidth] = useState(0); | ||
const [height, setHeight] = useState(0); | ||
|
||
useEffect(() => { | ||
if (height && width) { | ||
onResize(); | ||
} | ||
}, [height, width]); | ||
|
||
const onResize = () => { | ||
const container = conRef.current; | ||
setWidth(container?.clientWidth ?? 0); | ||
setHeight(container?.clientHeight ?? 0); | ||
}; | ||
|
||
return ( | ||
<ReactResizeDetector onResize={onResize}> | ||
<Container | ||
ref={conRef} | ||
$style={props.style} | ||
style={{ | ||
fontSize: props.autoHeight | ||
? `${height < width ? height : width}px` | ||
: props.iconSize, | ||
background: props.style.background, | ||
}} | ||
onClick={() => props.onEvent("click")} | ||
> | ||
{props.icon} | ||
</Container> | ||
</ReactResizeDetector> | ||
); | ||
}; | ||
|
||
let IconBasicComp = (function () { | ||
return new UICompBuilder(childrenMap, (props) => <IconView {...props} />) | ||
.setPropertyViewFn((children) => ( | ||
<> | ||
<Section name={sectionNames.basic}> | ||
{children.icon.propertyView({ | ||
label: trans("iconComp.icon"), | ||
IconType: "All", | ||
})} | ||
{children.autoHeight.propertyView({ | ||
label: trans("iconComp.autoSize"), | ||
})} | ||
{!children.autoHeight.getView() && | ||
children.iconSize.propertyView({ | ||
label: trans("iconComp.iconSize"), | ||
})} | ||
</Section> | ||
<Section name={sectionNames.interaction}> | ||
{children.onEvent.getPropertyView()} | ||
</Section> | ||
<Section name={sectionNames.layout}> | ||
{hiddenPropertyView(children)} | ||
</Section> | ||
<Section name={sectionNames.style}> | ||
{children.style.getPropertyView()} | ||
</Section> | ||
</> | ||
)) | ||
.build(); | ||
})(); | ||
|
||
IconBasicComp = class extends IconBasicComp { | ||
override autoHeight(): boolean { | ||
return false; | ||
} | ||
}; | ||
|
||
export const IconComp = withExposingConfigs(IconBasicComp, [ | ||
NameConfigHidden, | ||
]); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is ANTDICON in timelineComp?