Skip to content

Commit

Permalink
Changed code space from tab to two spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
wozitto committed Apr 11, 2024
1 parent b6ce4f7 commit a7826c4
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ One of its primary use cases is to make dynamic and conditional `className` prop
import React, { useState } from 'react';

export default function Button (props) {
const [isPressed, setIsPressed] = useState(false);
const [isHovered, setIsHovered] = useState(false);

let btnClass = 'btn';
if (isPressed) btnClass += ' btn-pressed';
else if (isHovered) btnClass += ' btn-over';

return (
<button
className={btnClass}
onMouseDown={() => setIsPressed(true)}
onMouseUp={() => setIsPressed(false)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
{props.label}
</button>
);
const [isPressed, setIsPressed] = useState(false);
const [isHovered, setIsHovered] = useState(false);

let btnClass = 'btn';
if (isPressed) btnClass += ' btn-pressed';
else if (isHovered) btnClass += ' btn-over';

return (
<button
className={btnClass}
onMouseDown={() => setIsPressed(true)}
onMouseUp={() => setIsPressed(false)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
{props.label}
</button>
);
}
```

Expand All @@ -111,35 +111,35 @@ import React, { useState } from 'react';
import classNames from 'classnames';

export default function Button (props) {
const [isPressed, setIsPressed] = useState(false);
const [isHovered, setIsHovered] = useState(false);

const btnClass = classNames({
btn: true,
'btn-pressed': isPressed,
'btn-over': !isPressed && isHovered,
});

return (
<button
className={btnClass}
onMouseDown={() => setIsPressed(true)}
onMouseUp={() => setIsPressed(false)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
{props.label}
</button>
);
const [isPressed, setIsPressed] = useState(false);
const [isHovered, setIsHovered] = useState(false);

const btnClass = classNames({
btn: true,
'btn-pressed': isPressed,
'btn-over': !isPressed && isHovered,
});

return (
<button
className={btnClass}
onMouseDown={() => setIsPressed(true)}
onMouseUp={() => setIsPressed(false)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
{props.label}
</button>
);
}
```

Because you can mix together object, array and string arguments, supporting optional `className` props is also simpler as only truthy arguments get included in the result:

```js
const btnClass = classNames('btn', this.props.className, {
'btn-pressed': isPressed,
'btn-over': !isPressed && isHovered,
'btn-pressed': isPressed,
'btn-over': !isPressed && isHovered,
});
```

Expand Down Expand Up @@ -170,9 +170,9 @@ _Note that in ES2015 environments, it may be better to use the "dynamic class na
const classNames = require('classnames/bind');

const styles = {
foo: 'abc',
bar: 'def',
baz: 'xyz',
foo: 'abc',
bar: 'def',
baz: 'xyz',
};

const cx = classNames.bind(styles);
Expand Down

0 comments on commit a7826c4

Please sign in to comment.