Skip to content

Commit

Permalink
Minor simplifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
willrogers committed Dec 7, 2020
1 parent 8dc2d16 commit b4420e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
25 changes: 5 additions & 20 deletions src/ui/widgets/Label/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ const LabelProps = {
font: FontPropOpt,
foregroundColor: ColorPropOpt,
backgroundColor: ColorPropOpt,
border: BorderPropOpt,
transform: StringPropOpt
border: BorderPropOpt
};

const LabelWidgetProps = {
...LabelProps,
...WidgetPropType
};

type LabelWidget = InferWidgetProps<typeof LabelWidgetProps>;

export const LabelComponent = (
props: InferWidgetProps<typeof LabelProps>
): JSX.Element => {
const style: CSSProperties = commonCss(props);
const { transparent = false, textAlign = "center", text = "" } = props;
const { textAlign = "center", text = "" } = props;
const className = props.className ?? `Label ${classes.Label}`;
// Since display is "flex", use "flex-start" and "flex-end" to align
// the content.
Expand All @@ -49,19 +46,7 @@ export const LabelComponent = (
alignment = "flex-end";
}
style["justifyContent"] = alignment;
style["color"] = props.foregroundColor?.toString();
style["backgroundColor"] = props.backgroundColor?.toString();
// Transparent prop overrides backgroundColor.
if (transparent) {
style["backgroundColor"] = "transparent";
}
if (props.visible) {
style["visibility"] = "visible";
}

if (props.transform) {
style["transform"] = props.transform;
}
// Simple component to display text - defaults to black text and dark grey background
return (
<div className={className} style={style}>
Expand All @@ -70,8 +55,8 @@ export const LabelComponent = (
);
};

export const Label = (props: LabelWidget): JSX.Element => (
<Widget baseWidget={LabelComponent} {...props} />
);
export const Label = (
props: InferWidgetProps<typeof LabelWidgetProps>
): JSX.Element => <Widget baseWidget={LabelComponent} {...props} />;

registerWidget(Label, LabelWidgetProps, "label");
2 changes: 0 additions & 2 deletions src/ui/widgets/widgetProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export const WidgetPropType = {
rules: RulesPropOpt,
actions: ActionsPropType,
tooltip: StringPropOpt,
resolvedTooltip: StringPropOpt,
menuWrapper: BoolPropOpt,
border: BorderPropOpt,
visible: BoolPropOpt
};
Expand Down

0 comments on commit b4420e4

Please sign in to comment.