mirror of
https://github.com/pezkuwichain/pezkuwi-extension.git
synced 2026-10-31 07:29:49 +00:00
- @pezkuwi/dev, dev-test, dev-ts ^0.86.3 in the root and in every workspace package (they still asked for 0.84.3) - tsconfig.base target ES2022, the @pezkuwi/dev default; it carries the ErrorOptions type for `cause` - rethrown errors carry the original as `cause`; rejections are normalised to Error - page/messaging: the typed subscriber is called directly, not as `Function` - chrome mock: constant results through Promise.resolve - useLedger: drop a construction every branch below repeated - InputWithLabel: onKeyDown instead of the deprecated onKeyPress - Account: toggleActions + 1 instead of a pre-increment of a parameter - optional chains where a guard tested the same value - specs: mount<React.Component> so the wrappers are not `any`-typed - AccountsStore.set keeps its async override of KeyringStore.set: BaseStore.set handles its own failure, so it never rejects - extension-chains keeps its ChainProperties assertion: the package's own build does not load the type augmentation - the existing React Compiler findings (37, react-hooks rules only) are recorded in eslint-suppressions.json; a new one fails lint
114 lines
2.5 KiB
TypeScript
114 lines
2.5 KiB
TypeScript
// Copyright 2019-2026 @pezkuwi/extension-ui authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import React, { useCallback, useEffect } from 'react';
|
|
|
|
import Checkmark from '../assets/checkmark.svg';
|
|
import { styled } from '../styled.js';
|
|
|
|
interface Props {
|
|
checked: boolean;
|
|
indeterminate?: boolean;
|
|
className?: string;
|
|
label: string;
|
|
onChange?: (checked: boolean) => void;
|
|
onClick?: () => void;
|
|
}
|
|
|
|
function Checkbox ({ checked, className, indeterminate, label, onChange, onClick }: Props): React.ReactElement<Props> {
|
|
const checkboxRef = React.useRef<HTMLInputElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (checkboxRef.current) {
|
|
checkboxRef.current.indeterminate = !!indeterminate;
|
|
}
|
|
}, [indeterminate]);
|
|
|
|
const _onChange = useCallback(
|
|
(event: React.ChangeEvent<HTMLInputElement>) => onChange?.(event.target.checked),
|
|
[onChange]
|
|
);
|
|
|
|
const _onClick = useCallback(
|
|
() => onClick?.(),
|
|
[onClick]
|
|
);
|
|
|
|
return (
|
|
<div className={className}>
|
|
<label>
|
|
{label}
|
|
<input
|
|
checked={checked && !indeterminate}
|
|
onChange={_onChange}
|
|
onClick={_onClick}
|
|
ref={checkboxRef}
|
|
type='checkbox'
|
|
/>
|
|
<span />
|
|
</label>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default styled(Checkbox)<Props>`
|
|
margin: var(--boxMargin);
|
|
|
|
label {
|
|
display: block;
|
|
position: relative;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
padding-left: 24px;
|
|
padding-top: 1px;
|
|
color: var(--subTextColor);
|
|
font-size: var(--fontSize);
|
|
line-height: var(--lineHeight);
|
|
|
|
& input {
|
|
position: absolute;
|
|
opacity: 0;
|
|
cursor: pointer;
|
|
height: 0;
|
|
width: 0;
|
|
}
|
|
|
|
& span {
|
|
position: absolute;
|
|
top: 4px;
|
|
left: 0;
|
|
height: 16px;
|
|
width: 16px;
|
|
border-radius: var(--borderRadius);
|
|
background-color: var(--readonlyInputBackground);
|
|
border: 1px solid var(--inputBorderColor);
|
|
border: 1px solid var(--inputBorderColor);
|
|
|
|
&:after {
|
|
content: '';
|
|
display: none;
|
|
width: 13px;
|
|
height: 10px;
|
|
position: absolute;
|
|
left: 1px;
|
|
top: 2px;
|
|
mask: url(${Checkmark});
|
|
mask-size: cover;
|
|
background: var(--primaryColor);
|
|
}
|
|
}
|
|
|
|
&:hover input ~ span {
|
|
background-color: var(--inputBackground);
|
|
}
|
|
|
|
input:checked ~ span:after {
|
|
display: block;
|
|
}
|
|
|
|
input:indeterminate ~ span {
|
|
background: var(--primaryColor)
|
|
}
|
|
}
|
|
`;
|