Files
custum-hyprpanel/src/components/bar/shared/Module.tsx
ilikestreet e0917ffb28 feat: no update w/ autohide option & add option to swap netstat icon … (#591)
* feat: no update w/ autohide option & add option to swap netstat icon for up/down links

* Update src/scss/style/bar/bar.scss

* Update src/components/bar/shared/Module.tsx

* Update src/components/bar/settings/config.tsx

* Update src/options.ts

* Apply suggestions from code review

* move visibilty to updatesIcon func

---------

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
2024-12-24 02:34:56 -08:00

95 lines
2.7 KiB
TypeScript

import { bind, Variable } from 'astal';
import { BarBoxChild, BarModule } from 'src/lib/types/bar';
import { BarButtonStyles } from 'src/lib/types/options';
import options from 'src/options';
const { style } = options.theme.bar.buttons;
const undefinedVar = Variable(undefined);
export const Module = ({
icon,
textIcon,
useTextIcon = bind(Variable(false)),
label,
tooltipText,
boxClass,
isVis,
props = {},
showLabelBinding = bind(undefinedVar),
showLabel,
labelHook,
hook,
}: BarModule): BarBoxChild => {
const getIconWidget = (useTxtIcn: boolean): JSX.Element | undefined => {
let iconWidget: JSX.Element | undefined;
if (icon !== undefined && !useTxtIcn) {
iconWidget = <icon className={`txt-icon bar-button-icon module-icon ${boxClass}`} icon={icon} />;
} else if (textIcon !== undefined) {
iconWidget = <label className={`txt-icon bar-button-icon module-icon ${boxClass}`} label={textIcon} />;
}
return iconWidget;
};
const componentClass = Variable.derive(
[bind(style), showLabelBinding],
(style: BarButtonStyles, shwLabel: boolean) => {
const shouldShowLabel = shwLabel || showLabel;
const styleMap = {
default: 'style1',
split: 'style2',
wave: 'style3',
wave2: 'style3',
};
return `${boxClass} ${styleMap[style]} ${!shouldShowLabel ? 'no-label' : ''}`;
},
);
const componentChildren = Variable.derive(
[showLabelBinding, useTextIcon],
(showLabel: boolean, forceTextIcon: boolean): JSX.Element[] => {
const childrenArray = [];
const iconWidget = getIconWidget(forceTextIcon);
if (iconWidget !== undefined) {
childrenArray.push(iconWidget);
}
if (showLabel) {
childrenArray.push(
<label
className={`bar-button-label module-label ${boxClass}`}
label={label ?? ''}
setup={labelHook}
/>,
);
}
return childrenArray;
},
);
const component: JSX.Element = (
<box
tooltipText={tooltipText}
className={componentClass()}
setup={hook}
onDestroy={() => {
componentChildren.drop();
componentClass.drop();
}}
>
{componentChildren()}
</box>
);
return {
component,
tooltip_text: tooltipText,
isVis: isVis,
boxClass,
props,
};
};