Skip to content

Commit

Permalink
feat: hide preview button when the text in not being edited (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-santos authored Jul 25, 2024
1 parent 39d2fea commit b1ed5af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 39 deletions.
13 changes: 5 additions & 8 deletions app/renderer/src/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ import {
export type CheckboxProps = {
label?: string;
asPrimary?: boolean;
hidden?: boolean;
} & React.HTMLProps<HTMLInputElement>;

export const Checkbox = React.forwardRef<
HTMLInputElement,
CheckboxProps
>(({ id, label, name, disabled, asPrimary, ...props }, ref) => {
>(({ id, label, name, disabled, asPrimary, hidden, ...props }, ref) => {
return (
<StyledCheckbox
htmlFor={id}
disabled={disabled}
asPrimary={asPrimary}
>
<StyledCheckbox htmlFor={id} asPrimary={asPrimary}>
<input
type="checkbox"
name={name}
Expand All @@ -28,8 +25,8 @@ export const Checkbox = React.forwardRef<
disabled={disabled}
{...props}
/>
<StyledCheckboxBox />
<StyledCheckboxLabel>{label}</StyledCheckboxLabel>
<StyledCheckboxBox hidden={hidden} />
<StyledCheckboxLabel>{hidden ? "" : label}</StyledCheckboxLabel>
</StyledCheckbox>
);
});
Expand Down
7 changes: 1 addition & 6 deletions app/renderer/src/components/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import { CheckboxProps } from "./Checkbox";
export const Radio = React.forwardRef<HTMLInputElement, CheckboxProps>(
({ id, label, name, disabled, asPrimary, ...props }, ref) => {
return (
<StyledCheckbox
htmlFor={id}
disabled={disabled}
tabIndex={0}
asPrimary={asPrimary}
>
<StyledCheckbox htmlFor={id} tabIndex={0} asPrimary={asPrimary}>
<input
type="radio"
name={name}
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/routes/Tasks/TaskDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const TaskDetails = React.forwardRef<HTMLDivElement, Props>(
Description
<Checkbox
label="preview"
disabled={!editingDescription}
hidden={!editingDescription}
onChange={showPreviewCallback}
asPrimary
/>
Expand Down
33 changes: 9 additions & 24 deletions app/renderer/src/styles/components/checkbox.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import styled, { css } from "styled-components/macro";
import { themes } from "styles/themes";

export const StyledCheckboxBox = styled.span`
export const StyledCheckboxBox = styled.span<{ hidden?: boolean }>`
width: 1.1em;
height: 1.1em;
display: flex;
display: ${({ hidden }) => (hidden ? "none" : "flex")};
align-items: center;
justify-content: center;
Expand Down Expand Up @@ -44,7 +44,6 @@ export const StyledCheckboxLabel = styled.span`
`;

export const StyledCheckbox = styled.label<{
disabled?: boolean;
asPrimary?: boolean;
}>`
& > input {
Expand Down Expand Up @@ -79,35 +78,21 @@ export const StyledCheckbox = styled.label<{
&:hover ${StyledCheckboxBox} {
box-shadow: ${(p) =>
p.disabled
? `0 0 0 0.2rem rgba(var(--${
p.asPrimary ? "color-primary" : "color-green"
}-rgb), 0)`
: `0 0 0 0.2rem rgba(var(--${
p.asPrimary ? "color-primary" : "color-green"
}-rgb), 0.16)`};
`0 0 0 0.2rem rgba(var(--${
p.asPrimary ? "color-primary" : "color-green"
}-rgb), 0.16)`};
}
&:active ${StyledCheckboxBox} {
box-shadow: ${(p) =>
p.disabled
? `0 0 0 0.4rem rgba(var(--${
p.asPrimary ? "color-primary" : "color-green"
}-rgb), 0)`
: `0 0 0 0.4rem rgba(var(--${
p.asPrimary ? "color-primary" : "color-green"
}-rgb), 0.16)`};
`0 0 0 0.4rem rgba(var(--${
p.asPrimary ? "color-primary" : "color-green"
}-rgb), 0.16)`};
}
&:hover ${StyledCheckboxLabel}, &:focus ${StyledCheckboxLabel} {
color: ${(p) =>
p.disabled
? "var(--color-disabled-text)"
: `var(--${p.asPrimary ? "color-primary" : "color-green"})`};
}
${StyledCheckboxLabel} {
color: ${(p) => p.disabled && "var(--color-disabled-text)"};
`var(--${p.asPrimary ? "color-primary" : "color-green"})`};
}
display: inline-flex;
Expand Down

0 comments on commit b1ed5af

Please sign in to comment.