Skip to content

Commit

Permalink
CSS Selectors (#310)
Browse files Browse the repository at this point in the history
### Summary

CSS Selectors for Google Analytics
  • Loading branch information
yatharth-b authored Mar 11, 2024
1 parent ae9fbb6 commit 669bba4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/AccountDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ export default function AccountDropdown({
items = [
{
label: <SignedInLabel state={state} />,
id: 'signed-in-label',
},
{
label: 'Sign out',
icon: faSignOutAlt,
onClick: (): void => state.signOut(),
id: 'sign-out-dropdown',
},
];
circleContent = <UserInitials state={state} />;
Expand All @@ -73,6 +75,7 @@ export default function AccountDropdown({
onClick: (): void => {
setLoginOpen(true);
},
id: 'sign-in-button-dropdown',
},
];
circleContent = (
Expand Down
8 changes: 7 additions & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ButtonProps = {
href?: string;
onClick?: (e: React.SyntheticEvent<HTMLDivElement>) => void;
children?: React.ReactNode;
id?: string;
};

export default function Button({
Expand All @@ -18,10 +19,13 @@ export default function Button({
href,
onClick,
children,
id,
}: ButtonProps): React.ReactElement {
if (disabled)
return (
<div className={classes('Button', 'disabled', className)}>{children}</div>
<div className={classes('Button', 'disabled', className)} id={id}>
{children}
</div>
);

if (href != null)
Expand All @@ -31,6 +35,7 @@ export default function Button({
href={href}
rel="noopener noreferrer"
target="_blank"
id={id}
>
{children}
</a>
Expand All @@ -46,6 +51,7 @@ export default function Button({
if (event.key === 'Enter' && onClick != null) onClick(event);
}}
role="button"
id={id}
>
{children}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/EventAdd/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export default function EventAdd({
className="button"
disabled={submitDisabled}
onClick={onSubmit}
id="event-add-button"
>
{event?.id ? 'Save' : 'Add'}
</Button>
Expand Down
3 changes: 3 additions & 0 deletions src/components/HeaderActionBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,23 @@ export default function HeaderActionBar({
label: 'Download image',
icon: faDownload,
onClick: onDownloadCalendar,
id: 'export-download',
});
}
if (enableExportCalendar) {
exportActions.push({
label: 'ICS (Calendar) file',
icon: faCalendarAlt,
onClick: onExportCalendar,
id: 'export-calendar',
});
}
if (enableCopyCrns) {
exportActions.push({
label: 'Copy CRNs to clipboard',
icon: faPaste,
onClick: onCopyCrns,
id: 'export-copy-crn',
});
}

Expand Down
1 change: 1 addition & 0 deletions src/components/HeaderDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ function VersionSelector({ state }: VersionSelectorProps): React.ReactElement {
true
);
}}
id="version-selector-dropdown"
/>

<Modal
Expand Down
10 changes: 8 additions & 2 deletions src/components/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type SelectProps<Id extends string | number> = {

// Ignored if `onClickNew` is not provided.
newLabel?: string;
id?: string;
};

export interface SelectOption<Id extends string | number> {
Expand Down Expand Up @@ -93,6 +94,7 @@ export default function Select<Id extends string | number>({
desiredItemWidth = null,
onClickNew,
newLabel = 'New',
id,
}: SelectProps<Id>): React.ReactElement {
const [opened, setOpened] = useState(false);

Expand Down Expand Up @@ -169,6 +171,7 @@ export default function Select<Id extends string | number>({
className={classes('Button', 'Select', className, `anchor-${menuAnchor}`)}
onClick={(): void => trySetOpened(!opened)}
style={style}
id={id}
>
<div className="text">{label}</div>
<FontAwesomeIcon fixedWidth icon={faCaretDown} />
Expand Down Expand Up @@ -295,7 +298,7 @@ export default function Select<Id extends string | number>({
</div>
))}
{onClickNew !== undefined && (
<div className="option">
<div className="option" id={id ? `${id}-new-button` : undefined}>
<Button className="option__button" onClick={onClickNew}>
<FontAwesomeIcon
fixedWidth
Expand Down Expand Up @@ -347,6 +350,7 @@ export type DropdownMenuProps = {
export interface DropdownMenuAction {
label: React.ReactNode;
icon?: IconDefinition;
id?: string;
onClick?: () => void;
}

Expand Down Expand Up @@ -377,17 +381,19 @@ export function DropdownMenu({
if (!disabled) setOpened(!opened);
}}
style={style}
id="export-button"
>
{children}
{opened && (
<div className="intercept" onClick={(): void => setOpened(false)} />
)}
{opened && (
<div className="option-container">
{items.map(({ label, icon, onClick }, i) => (
{items.map(({ label, icon, onClick, id }, i) => (
<div
className={classes('option', onClick == null && 'option--text')}
key={i}
id={id}
>
{onClick != null ? (
<Button className="option__button" onClick={onClick}>
Expand Down

0 comments on commit 669bba4

Please sign in to comment.