Skip to content

Commit b231863

Browse files
authored
Readme is not wip (#38)
* chore: update Readme * fix: hsvgradient mouse position
1 parent 1d6547f commit b231863

File tree

9 files changed

+331
-50
lines changed

9 files changed

+331
-50
lines changed

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

CONTRIBUTING.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Contributing Guidelines
2+
=======================
3+
4+
First of all, **thank you** for contributing, **you are awesome**!
5+
6+
Before starting, you should read, agree to, and follow these three things:
7+
8+
* [How to contribute?](#how-to-contribute)
9+
* [Pull Request Guidelines](#pull-request-guidelines)
10+
* [Code of Conduct](CODE_OF_CONDUCT.md)
11+
12+
---
13+
14+
## How to contribute?
15+
16+
### Report Bugs
17+
18+
Report bugs at: https://github.com/mikbry/material-ui-color-components/issues/new.
19+
20+
When reporting a bug, please include:
21+
22+
* Any details about your local setup which might be helpful in troubleshooting
23+
* Detailed steps to reproduce the bug. Where possible, please write a test case
24+
25+
If you are not able to do that, that's fine! Open an issue anyway and let us
26+
know as much information as you can. We will get back to you to determine the
27+
problem, and (hopefully) fix it.
28+
29+
### Fix Bugs
30+
31+
Check out the [open bugs](https://github.com/mikbry/material-ui-color-components/issues) - anything
32+
tagged with the **[easy pick]** label could be a good choice for newcomers (and
33+
we are willing to help you).
34+
35+
We have two kind of bugs: **[critical]** and **[bug]**. We tend to fix critical
36+
bugs as soon as possible. Feel free to come up with a patch before we do though!
37+
38+
### Implement Features
39+
40+
Look through the GitHub issues for features. Anything tagged with
41+
**[enhancement]** or **[feature]** is open to whoever wants to implement it.
42+
43+
If the issue is unclear or you are not sure what is expected, ask for more
44+
information by commenting on the issue.
45+
46+
### Submit Feedback
47+
48+
Any issue with the **[question]** label is open for feedback, so feel free to
49+
share your thoughts with us!
50+
51+
The best way to send feedback is to [create a new
52+
issue](https://github.com/mikbry/material-ui-color-components/issues/new) on GitHub.
53+
54+
If you are proposing a feature:
55+
56+
* Explain how you envision it working. Try to be as detailed as you can
57+
* Try to keep the scope as narrow as possible. This will help make it easier to
58+
implement
59+
* Feel free to include any code you might already have, even if it is
60+
just a rough idea. This is a volunteer-driven project, and contributions are
61+
welcome :)
62+
63+
Your issue will be flagged as **[feature request]** first, and if we agree on
64+
it, we will label it as **[feature]**, meaning it has been accepted and the
65+
feature will eventually be added to the project.
66+
67+
## Pull Request Guidelines
68+
69+
Here are a few rules to follow in order to make code reviews and discussions go
70+
more smoothly before maintainers accept and merge your work:
71+
72+
* you MUST run the test suite
73+
* you MUST write (or update) unit tests
74+
* you SHOULD write documentation
75+
76+
Please, write [commit messages that make
77+
sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html),
78+
and [rebase your branch](http://git-scm.com/book/en/Git-Branching-Rebasing)
79+
before submitting your Pull Request.
80+
81+
You may be asked to [squash your
82+
commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html)
83+
too. This is to "clean" your Pull Request before merging it (we don't want
84+
commits such as `fix tests`, `fix 2`, `fix 3`, etc.).
85+
86+
Also, while creating your Pull Request on GitHub, you MUST write a description
87+
which gives the context and/or explains why you are creating it.
88+
89+
For further information about creating a Pull Request, please read [this blog
90+
post](http://williamdurand.fr/2013/11/20/on-creating-pull-requests/).
91+
92+
Thank you!

README.md

Lines changed: 137 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,170 @@
44
[![codecov][codecov-image]][codecov-url]
55
[![NPM version][npm-image]][npm-url]
66
[![License][license-image]][license-url]
7+
[![minisize][min-image]][min-url]
78

89
[action-image]: https://github.com/mikbry/material-ui-color-components/workflows/Build%20and%20Deploy/badge.svg
910
[action-url]: https://mikbry.github.io/material-ui-color-components/
1011
[codecov-image]: https://codecov.io/gh/mikbry/material-ui-color-components/branch/master/graph/badge.svg?token=K4P0vnM5fh
1112
[codecov-url]: https://codecov.io/gh/mikbry/material-ui-color-components
1213
[npm-image]: https://img.shields.io/npm/v/material-ui-color-components.svg
1314
[npm-url]: https://npmjs.org/package/material-ui-color-components
14-
[license-image]: https://img.shields.io/npm/l/amaterial-ui-color-components.svg
15-
[License-url]:./LICENSE
15+
[license-image]: https://img.shields.io/github/license/mikbry/material-ui-color-components
16+
[License-url]:https://github.com/mikbry/material-ui-color-components/blob/master/LICENSE
17+
[min-image]:https://badgen.net/bundlephobia/min/material-ui-color-components
18+
[min-url]:https://bundlephobia.com/result?p=material-ui-color-components
1619

17-
> **[Prerelease, not ready for production]** Collections of color components for `material-ui` components for React Material-UI. Highly customizable and theming support !
20+
> Collections of color components for `material-ui`. No dependencies, small, highly customizable and theming support !
1821
1922
![Storybook](./images/wip.png)
2023

24+
## Why another ColorPicker ?
25+
26+
- Fully compatible with Material-UI : theming and low level components
27+
- Styled with `styled-components`
28+
- Highly customizable ColorPicker : gradient picker, palette, input format, deferred mode
29+
- Small in size (<30kb) without any extra dependencies
30+
- Use modern React hook and coding conventions
31+
- Documentation made with Storybook, using Component Story Format and MDX
32+
33+
## Documentation
34+
35+
Full documentation is available here :
36+
2137
https://mikbry.github.io/material-ui-color-components/
2238

23-
## Why ?
2439

25-
- Fully compatible with Material-UI : Theming and low level components
26-
- Highly customizable ColorPicker : gradient picker, palette, input format, deferred mode
27-
- Small in size without extra dependencies
28-
- Use modern hooks and coding conventions
40+
## Requirements
41+
- Works on modern browsers supporting ES6+ (Not compatible with IE)
42+
- Latest React, Styled-Component and Material-UI frameworks
2943

3044
## Install
3145

32-
`yarn add material-ui-color-components`
46+
```bash
47+
yarn add material-ui-color-components
48+
```
49+
50+
Or using npm
51+
```bash
52+
npm add material-ui-color-components
53+
```
54+
55+
## Usage
56+
57+
you need to have in your dependencies:
58+
59+
```
60+
"@material-ui/core": "^4.9.5",
61+
"material-ui-popup-state": "^1.5.3",
62+
"prop-types": "15.7.2",
63+
"react": "^16.12.0",
64+
"react-dom": "^16.12.0",
65+
"styled-components": "^5.0.1"
66+
```
67+
68+
`material-ui-color-components` bring 5 components.
69+
70+
### `<ColorPicker/>`
71+
72+
A popover component to display a color tool box (use `ColorBox`)
73+
```javascript
74+
import { ColorPicker } from 'material-ui-color-components';
75+
76+
export const Container = () => (
77+
<div>
78+
<ColorPicker defaultValue="transparent"/>
79+
</div>
80+
);
81+
```
82+
83+
At first it display a button + an input
84+
85+
[ColorPicker documentation](https://mikbry.github.io/material-ui-color-components/?path=/story/components-colorpicker--basic)
86+
87+
### `<ColorBox />`
88+
89+
A component to display a color tool box
90+
```javascript
91+
import { ColorBox } from 'material-ui-color-components';
92+
93+
export const Container = () => (
94+
<div>
95+
<ColorBox defaultValue="transparent"/>
96+
</div>
97+
);
98+
```
99+
100+
[ColorBox documentation](https://mikbry.github.io/material-ui-color-components/?path=/story/components-colorbox--basic)
101+
102+
### `<ColorInput />`
103+
104+
An input component to display/edit color values in different format (plain, hex, rgb, hsl, hsv).
105+
106+
```javascript
107+
import { ColorInput } from 'material-ui-color-components';
108+
109+
export const Container = () => (
110+
<div>
111+
<ColorInput defaultValue="red"/>
112+
</div>
113+
);
114+
```
115+
116+
[ColorInput documentation](https://mikbry.github.io/material-ui-color-components/?path=/story/components-colorinput--basic)
117+
118+
### `<ColorPalette />`
119+
120+
A component to display a grid of color buckets.
121+
122+
```javascript
123+
import { ColorPalette } from 'material-ui-color-components';
33124

125+
const palette = {
126+
red: '#ff0000',
127+
blue: '#0000ff',
128+
green: '#00ff00',
129+
yellow: 'yellow',
130+
cyan: 'cyan',
131+
lime: 'lime',
132+
gray: 'gray',
133+
orange: 'orange',
134+
purple: 'purple',
135+
black: 'black',
136+
white: 'white',
137+
pink: 'pink',
138+
darkBlue: 'darkBlue',
139+
};
34140

141+
export const Container = () => (
142+
<div>
143+
<ColorPalette palette={palette} />
144+
</div>
145+
);
146+
```
35147

36-
## `<ColorPicker/>`
148+
[ColorPalette documentation](https://mikbry.github.io/material-ui-color-components/?path=/story/components-colorpalette--basic)
37149

38-
TODO : doc
150+
### `<ColorButton />`
39151

40-
## `<ColorBox />`
152+
Displays a button filled with a color
41153

42-
TODO : doc
154+
```javascript
155+
import { ColorButton } from 'material-ui-color-components';
43156

44-
## `<ColorInput />`
157+
export const Container = () => (
158+
<div>
159+
<ColorButton red="red"/>
160+
</div>
161+
);
162+
```
45163

46-
TODO : doc
164+
[ColorButton documentation](https://mikbry.github.io/material-ui-color-components/?path=/story/components-colorbutton--basic)
47165

48-
## `<ColorPalette />`
166+
## Contribute
49167

50-
TODO : doc
168+
Contributions welcome! Read the [contribution guidelines](CONTRIBUTING.md) first.
51169

52-
## `<ColorButton />`
53170

54-
TODO : doc
171+
## License
55172

56-
## WIP
57-
TODO list
58-
- [x] init project
59-
- [x] create simple color picker
60-
- [x] create color tools/helpers
61-
- [x] publish
62-
- [ ] finish tests / coverage
63-
- [ ] documentation
173+
Released under MIT License

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
},
9393
"coverageReporters": [
9494
"text",
95-
"html"
95+
"html",
96+
"lcov"
9697
],
9798
"moduleFileExtensions": [
9899
"js",

src/components/ColorBox/HSVGradient.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ const HSVGradient = ({ className, color, onChange, ...props }) => {
107107
}
108108

109109
const convertMousePosition = (event, ref) => {
110-
const { clientX, clientY } = event;
111-
const { offsetLeft, offsetTop } = ref.offsetParent;
112-
const pos = { x: clientX - offsetLeft - 6, y: clientY - offsetTop - 6 };
110+
const { pageX, pageY } = event;
111+
const bounds = ref.getBoundingClientRect();
112+
const pos = { x: pageX - bounds.left, y: pageY - bounds.top };
113113
if (pos.x < 0) {
114114
pos.x = 0;
115115
}

src/components/ColorBox/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const useStyles = () =>
2929
makeStyles(theme => ({
3030
root: {
3131
backgroundColor: theme.palette.background.paper,
32-
position: 'absolute',
32+
position: 'relative',
3333
width: 'min-content',
3434
height: 'min-content',
3535
padding: '0px',

stories/ColorPicker.stories.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ export default {
2828

2929
const style = { margin: '48px' };
3030

31-
export const Basic = () => (
32-
<div style={style}>
33-
<ColorPicker defaultValue="#000" />
34-
</div>
35-
);
31+
export const Basic = () => <ColorPicker defaultValue="#000" />;
3632
Basic.story = {
3733
parameters: { defaultValue: '#000' },
3834
};

0 commit comments

Comments
 (0)