Update how conditional elements are rendered for bar modules. (#688)

This commit is contained in:
Jas Singh
2025-01-03 00:23:10 -08:00
committed by GitHub
parent 0533965c86
commit e525d9e03a
6 changed files with 105 additions and 37 deletions

View File

@@ -13,6 +13,26 @@ const { leftClick, rightClick, middleClick, scrollDown, scrollUp } = options.bar
const ClientTitle = (): BarBoxChild => {
const { custom_title, class_name, label, icon, truncation, truncation_size } = options.bar.windowtitle;
const ClientIcon = ({ client }: ClientIconProps): JSX.Element => {
return <label className={'bar-button-icon windowtitle txt-icon bar'} label={getWindowMatch(client).icon} />;
};
const ClientLabel = ({
client,
useCustomTitle,
useClassName,
showIcon,
truncate,
truncationSize,
}: ClientLabelProps): JSX.Element => {
return (
<label
className={`bar-button-label windowtitle ${showIcon ? '' : 'no-icon'}`}
label={truncateTitle(getTitle(client, useCustomTitle, useClassName), truncate ? truncationSize : -1)}
/>
);
};
const componentClassName = Variable.derive(
[bind(options.theme.bar.buttons.style), bind(label)],
(style: string, showLabel: boolean) => {
@@ -48,22 +68,18 @@ const ClientTitle = (): BarBoxChild => {
const children: JSX.Element[] = [];
if (showIcon) {
children.push(
<label
className={'bar-button-icon windowtitle txt-icon bar'}
label={getWindowMatch(client).icon}
/>,
);
children.push(<ClientIcon client={client} />);
}
if (showLabel) {
children.push(
<label
className={`bar-button-label windowtitle ${showIcon ? '' : 'no-icon'}`}
label={truncateTitle(
getTitle(client, useCustomTitle, useClassName),
truncate ? truncationSize : -1,
)}
<ClientLabel
client={client}
useCustomTitle={useCustomTitle}
useClassName={useClassName}
truncate={truncate}
truncationSize={truncationSize}
showIcon={showIcon}
/>,
);
}
@@ -122,4 +138,17 @@ const ClientTitle = (): BarBoxChild => {
};
};
interface ClientIconProps {
client: AstalHyprland.Client;
}
interface ClientLabelProps {
client: AstalHyprland.Client;
useCustomTitle: boolean;
useClassName: boolean;
showIcon: boolean;
truncate: boolean;
truncationSize: number;
}
export { ClientTitle };