Skip to content

Commit 765f777

Browse files
committed
Merge branch 'pre-custom-dns-fixes'
2 parents 8154f1d + 88c0a52 commit 765f777

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

gui/src/renderer/components/Switch.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import styled from 'styled-components';
33
import { colors } from '../../config.json';
4+
import { assignToRef } from '../lib/utilityHooks';
45

56
interface IProps {
67
id?: string;
@@ -10,6 +11,7 @@ interface IProps {
1011
onChange?: (isOn: boolean) => void;
1112
className?: string;
1213
disabled?: boolean;
14+
forwardedRef?: React.Ref<HTMLDivElement>;
1315
}
1416

1517
interface IState {
@@ -75,15 +77,16 @@ export default class Switch extends React.PureComponent<IProps, IState> {
7577
public render() {
7678
return (
7779
<SwitchContainer
80+
ref={this.refCallback}
7881
id={this.props.id}
7982
role="checkbox"
8083
aria-labelledby={this.props['aria-labelledby']}
8184
aria-describedby={this.props['aria-describedby']}
8285
aria-checked={this.props.isOn}
83-
ref={this.containerRef}
8486
onClick={this.handleClick}
8587
disabled={this.props.disabled ?? false}
8688
aria-disabled={this.props.disabled ?? false}
89+
tabIndex={-1}
8790
className={this.props.className}>
8891
<Knob
8992
disabled={this.props.disabled ?? false}
@@ -95,6 +98,11 @@ export default class Switch extends React.PureComponent<IProps, IState> {
9598
);
9699
}
97100

101+
private refCallback = (element: HTMLDivElement | null) => {
102+
assignToRef(element, this.containerRef);
103+
assignToRef(element, this.props.forwardedRef);
104+
};
105+
98106
private handleClick = () => {
99107
if (this.props.disabled) {
100108
return;

gui/src/renderer/components/cell/CellButton.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@ import { colors } from '../../../config.json';
44
import { CellDisabledContext } from './Container';
55
import { CellSectionContext } from './Section';
66

7-
interface IStyledCellButtonProps {
7+
interface IStyledCellButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
88
selected?: boolean;
99
containedInSection: boolean;
1010
}
1111

12-
const StyledCellButton = styled.button({}, (props: IStyledCellButtonProps) => ({
13-
display: 'flex',
14-
padding: '0 16px 0 22px',
15-
marginBottom: '1px',
16-
flex: 1,
17-
alignItems: 'center',
18-
alignContent: 'center',
19-
cursor: 'default',
20-
border: 'none',
21-
backgroundColor: props.selected
12+
export const StyledCellButton = styled.button({}, (props: IStyledCellButtonProps) => {
13+
const backgroundColor = props.selected
2214
? colors.green
2315
: props.containedInSection
2416
? colors.blue40
25-
: colors.blue,
26-
':not(:disabled):hover': {
27-
backgroundColor: props.selected ? colors.green : colors.blue80,
28-
},
29-
}));
17+
: colors.blue;
18+
const backgroundColorHover = props.selected ? colors.green : colors.blue80;
19+
20+
return {
21+
display: 'flex',
22+
padding: '0 16px 0 22px',
23+
marginBottom: '1px',
24+
flex: 1,
25+
alignItems: 'center',
26+
alignContent: 'center',
27+
cursor: 'default',
28+
border: 'none',
29+
backgroundColor,
30+
':not(:disabled):hover': {
31+
backgroundColor: props.onClick ? backgroundColorHover : backgroundColor,
32+
},
33+
};
34+
});
3035

3136
interface ICellButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3237
selected?: boolean;

gui/src/renderer/components/cell/Input.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import { mediumText } from '../common-styles';
55
import { CellDisabledContext } from './Container';
66
import StandaloneSwitch from '../Switch';
77

8-
export function Switch(props: StandaloneSwitch['props']) {
8+
export const Switch = React.forwardRef(function SwitchT(
9+
props: StandaloneSwitch['props'],
10+
ref: React.Ref<HTMLDivElement>,
11+
) {
912
const disabled = useContext(CellDisabledContext);
10-
return <StandaloneSwitch disabled={disabled} {...props} />;
11-
}
13+
return <StandaloneSwitch forwardedRef={ref} disabled={disabled} {...props} />;
14+
});
1215

1316
export const InputFrame = styled.div({
1417
flexGrow: 0,

gui/src/renderer/components/cell/Label.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ const StyledTintedIcon = styled(ImageView).attrs((props: IImageViewProps) => ({
3030
tintColor: props.tintColor ?? colors.white60,
3131
tintHoverColor: props.tintHoverColor ?? props.tintColor ?? colors.white60,
3232
}))((props: IImageViewProps) => ({
33-
[CellButton + ':hover &']: {
33+
':hover': {
34+
backgroundColor: props.tintColor,
35+
},
36+
[`${CellButton}:not(:disabled):hover &`]: {
3437
backgroundColor: props.tintHoverColor,
3538
},
3639
}));

gui/src/renderer/lib/utilityHooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function useCombinedRefs<T>(...refs: (React.Ref<T> | undefined)[]): React
1818
return useCallback((element: T | null) => refs.forEach((ref) => assignToRef(element, ref)), []);
1919
}
2020

21-
function assignToRef<T>(element: T | null, ref?: React.Ref<T>) {
21+
export function assignToRef<T>(element: T | null, ref?: React.Ref<T>) {
2222
if (typeof ref === 'function') {
2323
ref(element);
2424
} else if (ref && element) {

0 commit comments

Comments
 (0)