Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added disabled feature #68

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Burger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const Burger = (({
size = 32,
toggle,
toggled,
disabled = false
}) => {
const [toggledInternal, toggleInternal] = useState(false)

Expand All @@ -42,7 +43,7 @@ export const Burger = (({
const time = Math.max(0, duration)

const burgerStyles: CSSProperties = {
cursor: 'pointer',
cursor: disabled ? 'not-allowed' : 'pointer',
height: `${area}px`,
position: 'relative',
transition: `${time}s ${easing}`,
Expand Down
4 changes: 2 additions & 2 deletions src/Cross.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Cross = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="cross"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={o.burgerStyles}
tabIndex={0}
Expand Down
4 changes: 2 additions & 2 deletions src/Divide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Divide = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="divide"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={o.burgerStyles}
tabIndex={0}
Expand Down
4 changes: 2 additions & 2 deletions src/Fade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Fade = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="fade"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={o.burgerStyles}
tabIndex={0}
Expand Down
4 changes: 2 additions & 2 deletions src/Pivot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Pivot = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="pivot"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
4 changes: 2 additions & 2 deletions src/Rotate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Rotate = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="rotate"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
4 changes: 2 additions & 2 deletions src/Slant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Slant = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="slant"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
4 changes: 2 additions & 2 deletions src/Sling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Sling = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="sling"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
4 changes: 2 additions & 2 deletions src/Spin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Spin = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="spin"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
4 changes: 2 additions & 2 deletions src/Spiral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Spiral = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="spiral"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
4 changes: 2 additions & 2 deletions src/Squash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Squash = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="squash"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={o.burgerStyles}
tabIndex={0}
Expand Down
4 changes: 2 additions & 2 deletions src/Squeeze.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Squeeze = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="squeeze"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={o.burgerStyles}
tabIndex={0}
Expand Down
4 changes: 2 additions & 2 deletions src/Tilt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Tilt = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="tilt"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
4 changes: 2 additions & 2 deletions src/Turn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Turn = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="turn"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={o.burgerStyles}
tabIndex={0}
Expand Down
4 changes: 2 additions & 2 deletions src/Twirl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const Twirl = ((props) => (
aria-label={o.label}
aria-expanded={o.isToggled}
data-testid="twirl"
onClick={o.handler}
onKeyUp={(e) => e.key === 'Enter' && o.handler()}
onClick={props.disabled ? undefined : o.handler}
onKeyUp={props.disabled ? undefined : (e) => e.key === 'Enter' && o.handler()}
role="button"
style={{
...o.burgerStyles,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface CommonBurgerProps {
toggle?: Dispatch<SetStateAction<boolean>>
/** A way to provide your own state value. Can be used together with a state action (the `toggle` prop). */
toggled?: boolean;
/** Specifies if the hamburger should be disabled. */
disabled?: boolean;
}

export interface RenderOptions {
Expand Down