@pie-lib/tools 0.29.2-next.0 → 0.29.2-next.164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +7 -70
  2. package/esm/index.css +847 -0
  3. package/esm/index.js +13155 -0
  4. package/esm/index.js.map +1 -0
  5. package/esm/package.json +3 -0
  6. package/lib/anchor-utils.js +18 -74
  7. package/lib/anchor-utils.js.map +1 -1
  8. package/lib/anchor.js +20 -28
  9. package/lib/anchor.js.map +1 -1
  10. package/lib/index.js +1 -11
  11. package/lib/index.js.map +1 -1
  12. package/lib/protractor/graphic.js +68 -105
  13. package/lib/protractor/graphic.js.map +1 -1
  14. package/lib/protractor/index.js +35 -65
  15. package/lib/protractor/index.js.map +1 -1
  16. package/lib/rotatable.js +73 -141
  17. package/lib/rotatable.js.map +1 -1
  18. package/lib/ruler/graphic.js +29 -66
  19. package/lib/ruler/graphic.js.map +1 -1
  20. package/lib/ruler/index.js +43 -75
  21. package/lib/ruler/index.js.map +1 -1
  22. package/lib/ruler/unit-type.js +19 -36
  23. package/lib/ruler/unit-type.js.map +1 -1
  24. package/lib/ruler/unit.js +51 -88
  25. package/lib/ruler/unit.js.map +1 -1
  26. package/lib/style-utils.js +2 -9
  27. package/lib/style-utils.js.map +1 -1
  28. package/lib/transform-origin.js +2 -13
  29. package/lib/transform-origin.js.map +1 -1
  30. package/package.json +20 -10
  31. package/src/__tests__/rotatable.test.jsx +84 -41
  32. package/src/anchor.jsx +15 -16
  33. package/src/protractor/__tests__/graphic.test.jsx +57 -6
  34. package/src/protractor/__tests__/index.test.jsx +58 -6
  35. package/src/protractor/graphic.jsx +49 -54
  36. package/src/protractor/index.jsx +24 -22
  37. package/src/rotatable.jsx +23 -28
  38. package/src/ruler/__tests__/graphic.test.jsx +57 -16
  39. package/src/ruler/__tests__/index.test.jsx +70 -12
  40. package/src/ruler/__tests__/unit-type.test.jsx +59 -6
  41. package/src/ruler/__tests__/unit.test.jsx +61 -8
  42. package/src/ruler/graphic.jsx +11 -14
  43. package/src/ruler/index.jsx +25 -28
  44. package/src/ruler/unit-type.jsx +10 -9
  45. package/src/ruler/unit.jsx +25 -29
  46. package/src/__tests__/__snapshots__/rotatable.test.jsx.snap +0 -37
  47. package/src/protractor/__tests__/__snapshots__/graphic.test.jsx.snap +0 -1234
  48. package/src/protractor/__tests__/__snapshots__/index.test.jsx.snap +0 -40
  49. package/src/ruler/__tests__/__snapshots__/graphic.test.jsx.snap +0 -160
  50. package/src/ruler/__tests__/__snapshots__/index.test.jsx.snap +0 -45
  51. package/src/ruler/__tests__/__snapshots__/unit-type.test.jsx.snap +0 -12
  52. package/src/ruler/__tests__/__snapshots__/unit.test.jsx.snap +0 -30
@@ -1,13 +1,66 @@
1
- import toJson from 'enzyme-to-json';
2
- import { shallow } from 'enzyme';
1
+ import { render } from '@testing-library/react';
2
+ import { ThemeProvider, createTheme } from '@mui/material/styles';
3
3
  import { UnitType } from '../unit-type';
4
4
  import React from 'react';
5
5
 
6
6
  describe('unit-type', () => {
7
- describe('snapshot', () => {
8
- it('renders', () => {
9
- const wrapper = shallow(<UnitType classes={{}} label={'cm'} />);
10
- expect(toJson(wrapper)).toMatchSnapshot();
7
+ const theme = createTheme();
8
+
9
+ const renderComponent = (props = {}) => {
10
+ const defaultProps = {
11
+ label: 'cm',
12
+ ...props,
13
+ };
14
+
15
+ return render(
16
+ <ThemeProvider theme={theme}>
17
+ <svg>
18
+ <UnitType {...defaultProps} />
19
+ </svg>
20
+ </ThemeProvider>
21
+ );
22
+ };
23
+
24
+ describe('rendering', () => {
25
+ it('renders text element with label', () => {
26
+ const { container } = renderComponent({ label: 'cm' });
27
+ const text = container.querySelector('text');
28
+ expect(text).toBeInTheDocument();
29
+ expect(text).toHaveTextContent('cm');
30
+ });
31
+
32
+ it('renders with default position', () => {
33
+ const { container } = renderComponent();
34
+ const text = container.querySelector('text');
35
+ expect(text).toHaveAttribute('x', '8');
36
+ expect(text).toHaveAttribute('y', '14');
37
+ });
38
+
39
+ it('renders with custom position', () => {
40
+ const { container } = renderComponent({ x: 20, y: 30 });
41
+ const text = container.querySelector('text');
42
+ expect(text).toHaveAttribute('x', '20');
43
+ expect(text).toHaveAttribute('y', '30');
44
+ });
45
+
46
+ it('renders with custom fontSize', () => {
47
+ const { container } = renderComponent({ fontSize: 16 });
48
+ const text = container.querySelector('text');
49
+ expect(text).toBeInTheDocument();
50
+ });
51
+
52
+ it('renders with different labels', () => {
53
+ const { container, rerender } = renderComponent({ label: 'in' });
54
+ expect(container.querySelector('text')).toHaveTextContent('in');
55
+
56
+ rerender(
57
+ <ThemeProvider theme={theme}>
58
+ <svg>
59
+ <UnitType label="mm" />
60
+ </svg>
61
+ </ThemeProvider>
62
+ );
63
+ expect(container.querySelector('text')).toHaveTextContent('mm');
11
64
  });
12
65
  });
13
66
  });
@@ -1,15 +1,68 @@
1
- import toJson from 'enzyme-to-json';
2
- import { shallow } from 'enzyme';
1
+ import { render } from '@testing-library/react';
2
+ import { ThemeProvider, createTheme } from '@mui/material/styles';
3
3
  import { Unit } from '../unit';
4
4
  import React from 'react';
5
5
 
6
6
  describe('unit', () => {
7
- describe('snapshot', () => {
8
- it('renders', () => {
9
- const wrapper = shallow(
10
- <Unit index={2} width={30} height={20} last={false} config={{ ticks: 10 }} classes={{}} />,
11
- );
12
- expect(toJson(wrapper)).toMatchSnapshot();
7
+ const theme = createTheme();
8
+
9
+ const renderComponent = (props = {}) => {
10
+ const defaultProps = {
11
+ index: 2,
12
+ width: 30,
13
+ height: 20,
14
+ last: false,
15
+ config: { ticks: 10 },
16
+ ...props,
17
+ };
18
+
19
+ return render(
20
+ <ThemeProvider theme={theme}>
21
+ <svg>
22
+ <Unit {...defaultProps} />
23
+ </svg>
24
+ </ThemeProvider>
25
+ );
26
+ };
27
+
28
+ describe('rendering', () => {
29
+ it('renders group element with correct transform', () => {
30
+ const { container } = renderComponent({ index: 2, width: 30 });
31
+ const group = container.querySelector('g');
32
+ expect(group).toBeInTheDocument();
33
+ expect(group).toHaveStyle({ transform: 'translate(30px, 0px)' });
34
+ });
35
+
36
+ it('renders label with index value', () => {
37
+ const { container } = renderComponent({ index: 5 });
38
+ const text = container.querySelector('text');
39
+ expect(text).toHaveTextContent('5');
40
+ });
41
+
42
+ it('renders end tick when not last unit', () => {
43
+ const { container } = renderComponent({ last: false });
44
+ const lines = container.querySelectorAll('line');
45
+ // Should have end tick plus ticks based on config
46
+ expect(lines.length).toBeGreaterThan(0);
47
+ });
48
+
49
+ it('does not render end tick when last unit', () => {
50
+ const { container } = renderComponent({ last: true });
51
+ const group = container.querySelector('g');
52
+ expect(group).toBeInTheDocument();
53
+ });
54
+
55
+ it('renders correct number of tick marks', () => {
56
+ const { container } = renderComponent({ config: { ticks: 16 } });
57
+ const lines = container.querySelectorAll('line');
58
+ // Should render ticks based on config (16 ticks - 1 for range + 1 end tick = 16 total)
59
+ expect(lines.length).toBeGreaterThan(10);
60
+ });
61
+
62
+ it('renders with different width', () => {
63
+ const { container } = renderComponent({ index: 3, width: 40 });
64
+ const group = container.querySelector('g');
65
+ expect(group).toHaveStyle({ transform: 'translate(80px, 0px)' });
13
66
  });
14
67
  });
15
68
  });
@@ -1,17 +1,22 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
3
+ import { styled } from '@mui/material/styles';
4
4
  import UnitType from './unit-type';
5
5
  import range from 'lodash/range';
6
6
  import Unit from './unit';
7
7
  import { strokeColor, fillColor } from '../style-utils';
8
8
 
9
- const Bg = ({ width, height, className }) => <rect width={width} height={height} cx={0} cy={0} className={className} />;
9
+ const StyledBg = styled('rect')(({ theme }) => ({
10
+ stroke: strokeColor(theme),
11
+ strokeWidth: '2px',
12
+ fill: fillColor(theme),
13
+ }));
14
+
15
+ const Bg = ({ width, height }) => <StyledBg width={width} height={height} cx={0} cy={0} />;
10
16
 
11
17
  Bg.propTypes = {
12
18
  width: PropTypes.number.isRequired,
13
19
  height: PropTypes.number.isRequired,
14
- className: PropTypes.string.isRequired,
15
20
  };
16
21
 
17
22
  export class Graphic extends React.PureComponent {
@@ -20,18 +25,17 @@ export class Graphic extends React.PureComponent {
20
25
  height: PropTypes.number.isRequired,
21
26
  units: PropTypes.number.isRequired,
22
27
  unit: PropTypes.object.isRequired,
23
- classes: PropTypes.object.isRequired,
24
28
  };
25
29
 
26
30
  render() {
27
- const { width, height, classes, units, unit } = this.props;
31
+ const { width, height, units, unit } = this.props;
28
32
  const viewBox = `0 0 ${width} ${height}`;
29
33
  const unitWidth = width / units;
30
34
  const unitHeight = height;
31
35
 
32
36
  return (
33
37
  <svg viewBox={viewBox}>
34
- <Bg width={width} height={height} className={classes.bg} />
38
+ <Bg width={width} height={height} />
35
39
  <UnitType label={unit.type} />
36
40
  {range(1, units + 1).map((r) => (
37
41
  <Unit width={unitWidth} height={unitHeight} key={r} index={r} config={unit} last={r === units} />
@@ -40,12 +44,5 @@ export class Graphic extends React.PureComponent {
40
44
  );
41
45
  }
42
46
  }
43
- const styles = (theme) => ({
44
- bg: {
45
- stroke: strokeColor(theme),
46
- strokeWidth: '2px',
47
- fill: fillColor(theme),
48
- },
49
- });
50
47
 
51
- export default withStyles(styles)(Graphic);
48
+ export default Graphic;
@@ -1,19 +1,34 @@
1
1
  import React from 'react';
2
- import { withStyles } from '@material-ui/core/styles';
2
+ import { styled } from '@mui/material/styles';
3
3
  import Rotatable from '../rotatable';
4
- import classNames from 'classnames';
5
4
  import RulerGraphic from './graphic';
6
5
  import PropTypes from 'prop-types';
7
6
  import Anchor from '../anchor';
8
7
 
8
+ const StyledRuler = styled('div')(({ theme }) => ({
9
+ cursor: 'move',
10
+ position: 'relative',
11
+ backgroundColor: theme.palette.secondary.light,
12
+ opacity: 1.0,
13
+ border: `solid 0px ${theme.palette.primary.main}`,
14
+ }));
15
+
16
+ const StyledLeftAnchor = styled(Anchor)(() => ({
17
+ left: '-10px',
18
+ top: '40%',
19
+ }));
20
+
21
+ const StyledRightAnchor = styled(Anchor)(() => ({
22
+ right: '-10px',
23
+ top: '40%',
24
+ }));
25
+
9
26
  export class Ruler extends React.Component {
10
27
  static propTypes = {
11
28
  width: PropTypes.number,
12
29
  height: PropTypes.number,
13
30
  units: PropTypes.number.isRequired,
14
31
  measure: PropTypes.oneOf(['imperial', 'metric']).isRequired,
15
- classes: PropTypes.object.isRequired,
16
- className: PropTypes.string,
17
32
  startPosition: PropTypes.shape({
18
33
  left: PropTypes.number.isRequired,
19
34
  top: PropTypes.number.isRequired,
@@ -30,7 +45,7 @@ export class Ruler extends React.Component {
30
45
  };
31
46
 
32
47
  render() {
33
- const { classes, width, height, units, measure, className, startPosition, label, tickCount } = this.props;
48
+ const { width, height, units, measure, startPosition, label, tickCount } = this.props;
34
49
 
35
50
  const unit =
36
51
  measure === 'imperial'
@@ -44,38 +59,20 @@ export class Ruler extends React.Component {
44
59
  };
45
60
  return (
46
61
  <Rotatable
47
- className={className}
48
62
  startPosition={startPosition}
49
63
  handle={[
50
64
  { class: 'leftAnchor', origin: 'bottom right' },
51
65
  { class: 'rightAnchor', origin: 'bottom left' },
52
66
  ]}
53
67
  >
54
- <div className={classes.ruler} style={{ width: `${width}px`, height: `${height}px` }}>
68
+ <StyledRuler style={{ width: `${width}px`, height: `${height}px` }}>
55
69
  <RulerGraphic width={width} height={height} units={units} unit={unit} />
56
- <Anchor className={classNames('leftAnchor', classes.leftAnchor)} />
57
- <Anchor className={classNames('rightAnchor', classes.rightAnchor)} />
58
- </div>
70
+ <StyledLeftAnchor className="leftAnchor" />
71
+ <StyledRightAnchor className="rightAnchor" />
72
+ </StyledRuler>
59
73
  </Rotatable>
60
74
  );
61
75
  }
62
76
  }
63
- const styles = (theme) => ({
64
- ruler: {
65
- cursor: 'move',
66
- position: 'relative',
67
- backgroundColor: theme.palette.secondary.light,
68
- opacity: 1.0,
69
- border: `solid 0px ${theme.palette.primary.main}`,
70
- },
71
- leftAnchor: {
72
- left: '-10px',
73
- top: '40%',
74
- },
75
- rightAnchor: {
76
- right: '-10px',
77
- top: '40%',
78
- },
79
- });
80
77
 
81
- export default withStyles(styles)(Ruler);
78
+ export default Ruler;
@@ -1,14 +1,18 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { noSelect, strokeColor } from '../style-utils';
4
- import { withStyles } from '@material-ui/core/styles';
4
+ import { styled } from '@mui/material/styles';
5
+
6
+ const StyledText = styled('text')(({ theme }) => ({
7
+ ...noSelect(),
8
+ fill: strokeColor(theme),
9
+ }));
5
10
 
6
11
  export const UnitType = (props) => {
7
- const { classes, label, x, y, textAlign, fill, fontSize, stroke } = props;
12
+ const { label, x, y, textAlign, fill, fontSize, stroke } = props;
8
13
 
9
14
  return (
10
- <text
11
- className={classes.unitType}
15
+ <StyledText
12
16
  x={x}
13
17
  y={y}
14
18
  textAnchor={textAlign}
@@ -17,12 +21,11 @@ export const UnitType = (props) => {
17
21
  fontSize={fontSize}
18
22
  >
19
23
  {label}
20
- </text>
24
+ </StyledText>
21
25
  );
22
26
  };
23
27
 
24
28
  UnitType.propTypes = {
25
- classes: PropTypes.object.isRequired,
26
29
  label: PropTypes.string.isRequired,
27
30
  x: PropTypes.number,
28
31
  y: PropTypes.number,
@@ -40,6 +43,4 @@ UnitType.defaultProps = {
40
43
  y: 14,
41
44
  };
42
45
 
43
- export default withStyles((theme) => ({
44
- unitType: { ...noSelect(), fill: strokeColor(theme) },
45
- }))(UnitType);
46
+ export default UnitType;
@@ -1,18 +1,18 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
3
+ import { styled } from '@mui/material/styles';
4
4
  import { noSelect, strokeColor } from '../style-utils';
5
5
  import range from 'lodash/range';
6
6
 
7
- const Tick = withStyles((theme) => ({
8
- tick: {
9
- stroke: strokeColor(theme),
10
- },
11
- }))(({ x, height, bottom, classes, major, minor }) => {
7
+ const StyledTick = styled('line')(({ theme }) => ({
8
+ stroke: strokeColor(theme),
9
+ }));
10
+
11
+ const Tick = ({ x, height, bottom, major, minor }) => {
12
12
  const y1 = major ? bottom - height * 2 : minor ? bottom - height * 1.5 : bottom - height;
13
13
 
14
- return <line y1={y1} y2={bottom} x1={x} x2={x} className={classes.tick} />;
15
- });
14
+ return <StyledTick y1={y1} y2={bottom} x1={x} x2={x} />;
15
+ };
16
16
 
17
17
  const Ticks = ({ count, width, height }) => {
18
18
  return (
@@ -40,48 +40,44 @@ Ticks.propTypes = {
40
40
  height: PropTypes.number.isRequired,
41
41
  };
42
42
 
43
+ const StyledEndTick = styled('line')(({ theme }) => ({
44
+ stroke: strokeColor(theme),
45
+ strokeWidth: 1,
46
+ }));
47
+
48
+ const StyledLabel = styled('text')(({ theme }) => ({
49
+ textAnchor: 'end',
50
+ fontSize: '12px',
51
+ fill: strokeColor(theme),
52
+ ...noSelect(),
53
+ }));
54
+
43
55
  export class Unit extends React.Component {
44
56
  static propTypes = {
45
57
  index: PropTypes.number.isRequired,
46
58
  width: PropTypes.number.isRequired,
47
59
  height: PropTypes.number.isRequired,
48
- classes: PropTypes.object.isRequired,
49
60
  last: PropTypes.bool.isRequired,
50
61
  config: PropTypes.object.isRequired,
51
62
  };
52
63
 
53
64
  render() {
54
- const { index, width, height, classes, last, config } = this.props;
65
+ const { index, width, height, last, config } = this.props;
55
66
 
56
67
  const style = {
57
68
  transform: `translate(${width * (index - 1)}px, 0px)`,
58
69
  };
59
70
  return (
60
71
  <g style={style}>
61
- {!last && <line x1={width} y1={0} x2={width} y2={height} className={classes.endTick} />}
72
+ {!last && <StyledEndTick x1={width} y1={0} x2={width} y2={height} />}
62
73
 
63
74
  <Ticks count={config.ticks} width={width} height={height} />
64
- <text width={width} className={classes.label} x={width - 5} y={15}>
75
+ <StyledLabel width={width} x={width - 5} y={15}>
65
76
  {index}
66
- </text>
77
+ </StyledLabel>
67
78
  </g>
68
79
  );
69
80
  }
70
81
  }
71
82
 
72
- export default withStyles((theme) => ({
73
- endTick: {
74
- stroke: strokeColor(theme),
75
- strokeWidth: 1,
76
- },
77
- label: {
78
- textAnchor: 'end',
79
- fontSize: '12px',
80
- fill: strokeColor(theme),
81
- ...noSelect(),
82
- },
83
- base: {
84
- fill: 'none',
85
- stroke: 'red',
86
- },
87
- }))(Unit);
83
+ export default Unit;
@@ -1,37 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`rotatable snapshot renders 1`] = `
4
- <div
5
- className=""
6
- onMouseDown={[Function]}
7
- onMouseUp={[Function]}
8
- style={
9
- Object {
10
- "left": 0,
11
- "top": 0,
12
- "transform": " rotate(0deg)",
13
- "transformOrigin": undefined,
14
- }
15
- }
16
- >
17
- foo
18
- </div>
19
- `;
20
-
21
- exports[`rotatable snapshot renders with transforms 1`] = `
22
- <div
23
- className=""
24
- onMouseDown={[Function]}
25
- onMouseUp={[Function]}
26
- style={
27
- Object {
28
- "left": 0,
29
- "top": 0,
30
- "transform": "translate(10px, 10px) rotate(10deg)",
31
- "transformOrigin": "bottom left",
32
- }
33
- }
34
- >
35
- foo
36
- </div>
37
- `;