Skip to content

Commit 05ef6d7

Browse files
committed
Unify Button component implementations
* Merged SlimpSimpleButton, SimpleRoundButton and SimpleSmallButton into the master component SimpleButton. * Made styling more generic. * Removed the wrapper div from SimpleButton. * Replaced some custom button impelemtation with the generic SimpleButton. * Tweaked some layout problems arising from the button becoming a block element instead of an inline element as it should be. * Tweaked some individual buttons' styles. Were those broken always, by the previous twJoin/twMerge or these SimpleButton changes, I do not know. But they look at least ok now.
1 parent 7fa63c7 commit 05ef6d7

File tree

57 files changed

+382
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+382
-422
lines changed

ui/src/components/common/OpenDefaultMapButton.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { SimpleButton } from '../../uiComponents';
55
import { useNavigateToMap } from '../map/utils/useNavigateToMap';
66

77
type OpenDefaultMapButtonProps = {
8-
readonly containerClassName?: string;
8+
readonly className?: string;
99
readonly testId?: string;
1010
};
1111

1212
export const OpenDefaultMapButton = ({
13-
containerClassName,
13+
className,
1414
testId,
1515
}: OpenDefaultMapButtonProps) => {
1616
const { t } = useTranslation();
@@ -34,11 +34,7 @@ export const OpenDefaultMapButton = ({
3434
};
3535

3636
return (
37-
<SimpleButton
38-
containerClassName={containerClassName}
39-
onClick={onOpenMap}
40-
testId={testId}
41-
>
37+
<SimpleButton className={className} onClick={onOpenMap} testId={testId}>
4238
{t('map.open')}
4339
</SimpleButton>
4440
);

ui/src/components/common/info-container/DefaultHeaderButtons.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FC } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { FaChevronDown, FaChevronUp } from 'react-icons/fa';
44
import { Visible } from '../../../layoutComponents';
5-
import { SlimSimpleButton } from '../../stop-registry/stops/stop-details/layout';
5+
import { SimpleButton } from '../../../uiComponents';
66
import { InfoContainerHeaderButtonsProps } from './InfoContainerHeaderButtonsProps';
77

88
const testIds = {
@@ -25,19 +25,21 @@ export const DefaultHeaderButtons: FC<InfoContainerHeaderButtonsProps> = ({
2525
return (
2626
<div className="flex space-x-2">
2727
<Visible visible={isEditable && !isInEditMode}>
28-
<SlimSimpleButton
28+
<SimpleButton
29+
shape="slim"
2930
testId={testIds.editButton(testIdPrefix)}
3031
onClick={() => {
3132
setIsInEditMode(true);
3233
setIsExpanded(true);
3334
}}
3435
>
3536
{t('edit')}
36-
</SlimSimpleButton>
37+
</SimpleButton>
3738
</Visible>
3839

3940
<Visible visible={isExpandable && !isInEditMode}>
40-
<SlimSimpleButton
41+
<SimpleButton
42+
shape="slim"
4143
onClick={() => setIsExpanded((expanded) => !expanded)}
4244
inverted={!isExpanded}
4345
testId={testIds.toggle(testIdPrefix)}
@@ -47,7 +49,7 @@ export const DefaultHeaderButtons: FC<InfoContainerHeaderButtonsProps> = ({
4749
) : (
4850
<FaChevronDown className="text-tweaked-brand" aria-hidden />
4951
)}
50-
</SlimSimpleButton>
52+
</SimpleButton>
5153
</Visible>
5254
</div>
5355
);

ui/src/components/common/search/ExpandedSearchButtons.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,17 @@ export const ExpandedSearchButtons: FC<ExpandedSearchButtonsProps> = ({
3131
const { t } = useTranslation();
3232

3333
return (
34-
<Row className="flex justify-end bg-background py-4">
34+
<Row className="justify-end gap-4 bg-background px-10 py-4">
3535
<SimpleButton
36-
containerClassName="mr-4"
37-
className="h-12 w-32"
36+
className="w-32"
3837
inverted
3938
testId={testIds.hideButton(testIdPrefix)}
4039
onClick={toggleExpand}
4140
>
4241
{t('hide')}
4342
</SimpleButton>
4443
<SimpleButton
45-
containerClassName="mr-6"
46-
className="h-12 w-32"
44+
className="w-32"
4745
type={searchButtonType}
4846
onClick={searchButtonType === 'button' ? onSearch : undefined}
4947
testId={testIds.searchButton(testIdPrefix)}

ui/src/components/common/search/ResultSelector.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FC } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { useAppDispatch } from '../../../hooks';
44
import { resetSelectedRowsAction } from '../../../redux';
5-
import { SimpleSmallButton } from '../../../uiComponents';
5+
import { SimpleButton } from '../../../uiComponents';
66
import { DisplayedSearchResultType } from '../../../utils';
77
import { useSearch } from './useSearch';
88
import { SearchQueryParameterNames } from './useSearchQueryParser';
@@ -35,18 +35,22 @@ export const ResultSelector: FC = () => {
3535

3636
return (
3737
<div className="space-x-2">
38-
<SimpleSmallButton
38+
<SimpleButton
39+
shape="compact"
3940
inverted={displayedType !== DisplayedSearchResultType.Lines}
4041
onClick={displayLines}
41-
label={t('lines.lines')}
4242
testId={testIds.linesResultsButton}
43-
/>
44-
<SimpleSmallButton
43+
>
44+
{t('lines.lines')}
45+
</SimpleButton>
46+
<SimpleButton
47+
shape="compact"
4548
onClick={displayRoutes}
4649
inverted={displayedType !== DisplayedSearchResultType.Routes}
47-
label={t('lines.routes')}
4850
testId={testIds.routesResultsButton}
49-
/>
51+
>
52+
{t('lines.routes')}
53+
</SimpleButton>
5054
</div>
5155
);
5256
};

ui/src/components/forms/line/LineForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ export const LineForm: FC<LineFormProps> = ({ defaultValues, onSubmit }) => {
7474
/>
7575
</FormContainer>
7676
</Row>
77-
<Row className="mt-8 space-x-5">
77+
<Row className="mt-8 justify-end gap-5">
7878
<SimpleButton
79-
containerClassName="ml-auto"
8079
onClick={onCancel}
8180
inverted
8281
testId={testIds.cancelButton}

ui/src/components/forms/stop/components/TimingPlace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const TimingPlace: FC<TimingPlaceProps> = ({ className }) => {
3737
/>
3838

3939
<SimpleButton
40-
containerClassName="self-end ml-6"
40+
className="ml-6 self-end"
4141
onClick={() => dispatch(openTimingPlaceModalAction())}
4242
testId={testIds.addTimingPlaceButton}
4343
inverted

ui/src/components/main/MainPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export const MainPage: FC = () => {
3838
onClick={() => {
3939
window.location.href = LOGIN_URL;
4040
}}
41-
containerClassName="w-full justify-center"
42-
className="!px-6 !py-3 text-sm"
41+
className="mx-auto px-6 py-3 text-sm"
4342
>
4443
{t('welcomePage.login')}
4544
</SimpleButton>

ui/src/components/map/MapFooterActionsDropdown.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { Menu } from '@headlessui/react';
2-
import noop from 'lodash/noop';
32
import { FC } from 'react';
43
import { useTranslation } from 'react-i18next';
54
import { MdMoreVert } from 'react-icons/md';
65
import {
76
AlignDirection,
87
SimpleDropdownMenuItem,
98
SimpleDropdownMenuItems,
10-
SimpleRoundButton,
9+
getSimpleButtonClassNames,
1110
} from '../../uiComponents';
1211

1312
const testIds = {
@@ -35,17 +34,11 @@ export const MapFooterActionsDropdown: FC<MapFooterActionsDropdownProps> = ({
3534
<>
3635
<Menu.Button
3736
data-testid={testIds.menu}
38-
as="div"
39-
className="flex justify-around"
37+
className={getSimpleButtonClassNames(!open, disabled, 'round')}
38+
title={t('map.footerActionsTooltip')}
39+
aria-label={t('map.footerActionsTooltip')}
4040
>
41-
<SimpleRoundButton
42-
tooltip={t('map.footerActionsTooltip')}
43-
disabled={disabled}
44-
onClick={noop}
45-
inverted={!open}
46-
>
47-
<MdMoreVert aria-hidden className="text-4xl" />
48-
</SimpleRoundButton>
41+
<MdMoreVert aria-hidden className="text-4xl" />
4942
</Menu.Button>
5043
<SimpleDropdownMenuItems
5144
isOpen={open}

ui/src/components/map/MapFooterFullBar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const MapFooterFullBar: FC<MapFooterFullBarProps> = ({
7474
);
7575

7676
return (
77-
<Row testId={testIds.mapFooter} className="space-x-4 bg-white px-10 py-5">
77+
<Row testId={testIds.mapFooter} className="gap-4 bg-white px-10 py-5">
7878
<SimpleButton
7979
testId={testIds.drawRouteButton}
8080
onClick={onDrawRoute}
@@ -122,15 +122,16 @@ export const MapFooterFullBar: FC<MapFooterFullBarProps> = ({
122122
onCreateNewTerminal={onAddTerminal}
123123
/>
124124
<SimpleButton
125-
className="h-full !px-3 text-xl"
125+
shape="round"
126+
className="h-full text-xl"
126127
onClick={onDeleteRoute}
127128
disabled={!hasChangesInProgress || isRouteMetadataFormOpen}
128129
>
129130
<MdDelete aria-label={t('map.deleteRoute')} />
130131
</SimpleButton>
131132
<Visible visible={hasChangesInProgress && !isRouteMetadataFormOpen}>
132133
<SimpleButton
133-
containerClassName="!ml-auto"
134+
className="ml-auto"
134135
onClick={onCancel}
135136
disabled={!hasChangesInProgress}
136137
testId={testIds.cancelButton}

ui/src/components/map/StopSelection/StopSelectionListing.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ export const StopSelectionListing: FC<StopSelectionListingProps> = ({
180180

181181
{stops !== stopsToShow && (
182182
<SimpleButton
183-
className="my-2 py-1"
184-
containerClassName="flex justify-center"
183+
className="mx-auto my-2 py-1"
185184
inverted
186185
onClick={() => setShowAll(true)}
187186
testId={testIds.showAllButton}

0 commit comments

Comments
 (0)