@phelian/react-body-highlighter 2.0.5

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 GV79
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # [react-body-highlighter](https://www.npmjs.com/package/react-body-highlighter)
2
+
3
+ [![CI](https://github.com/GV79/react-body-highlighter/actions/workflows/main.yml/badge.svg)](https://github.com/GV79/react-body-highlighter/actions/workflows/main.yml)
4
+ [![Npm Version][npm-version-image]][npm-version-url]
5
+ [![License][license-image]][license-url]
6
+ [![Downloads][downloads-image]][downloads-url]
7
+
8
+ This package was created to have a body highlighter component compatible with React.js with minimal dependencies and some extra props for further functionality. The SVG polygons were leveraged from the React Native package [react-native-body-highlighter](https://github.com/HichamELBSI/react-native-body-highlighter).
9
+
10
+ <p align="center">
11
+ <img width="260" src="https://raw.githubusercontent.com/GV79/react-body-highlighter/master/image/anterior-example.png" alt="React Body Highlighter">
12
+ </p>
13
+
14
+ ## Installation
15
+
16
+ ```sh
17
+ $ npm install react-body-highlighter
18
+ ```
19
+
20
+ ```sh
21
+ $ yarn add react-body-highlighter
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ **Example**
27
+
28
+ [CodeSandbox](https://codesandbox.io/s/festive-swanson-995db?file=/src/App.tsx)
29
+
30
+ ```ts
31
+ import React from 'react';
32
+ import Model, { IExerciseData, IMuscleStats } from 'react-body-highlighter';
33
+
34
+ export default function Component() {
35
+ const data: IExerciseData[] = [
36
+ { name: 'Bench Press', muscles: ['chest', 'triceps', 'front-deltoids'] },
37
+ { name: 'Push Ups', muscles: ['chest'] },
38
+ ];
39
+
40
+ const handleClick = React.useCallback(({ muscle, data }: IMuscleStats) => {
41
+ const { exercises, frequency } = data;
42
+
43
+ alert(`You clicked the ${muscle}! You've worked out this muscle ${frequency} times through the following exercises: ${JSON.stringify(exercises)}`)
44
+
45
+ }, [data]);
46
+
47
+ return (
48
+ <Model
49
+ data={data}
50
+ style={{ width: '20rem', padding: '5rem' }}
51
+ onClick={handleClick}
52
+ />
53
+ );
54
+ }
55
+ ```
56
+
57
+ ## Props
58
+
59
+ All props are optional so if they are not passed to the component, they will fallback to default values or be undefined.
60
+
61
+ | Prop | Purpose | Type | Default |
62
+ | ----------------- | ------------------------------------------------------------------------------------------- | ---------------- | ----------------------- |
63
+ | bodyColor | Default color of unworked body muscle | String | `#B6BDC3` |
64
+ | data | Data array containing exercise JSON objects: `{ name: 'Bicep Curl', muscles: ['biceps'] }`. While the `name` and `muscles` attributes are required, you may optionally provide another attribute `frequency` to represent the exercise count/intensity. | Object[] | |
65
+ | highlightedColors | Array containing colors to display depending on frequency a muscle was worked (array[frequency-1] = color). For an example of how this works, see the CodeSandbox example above in the *Usage* section. | [] | `['#0984e3', '#74b9ff']` |
66
+ | onClick | Callback when muscle is clicked. The function will get passed a JSON object of the following structure: `{ muscle: 'name', stats: { exercises: [''], frequency: 0 } }` | (exercise) => {} | |
67
+ | style | CSSProperties style object that gets passed to SVG's parent container (div) | Object | |
68
+ | svgStyle | CSSProperties style object that gets passed to SVG element | Object | |
69
+ | type | Denotes type of model view (values: `anterior` or `posterior`) | String | `anterior` |
70
+
71
+ ## List of muscles/parts supported
72
+
73
+ ```
74
+ /* Back */
75
+ trapezius
76
+ upper-back
77
+ lower-back
78
+
79
+ /* Chest */
80
+ chest
81
+
82
+ /* Arms */
83
+ biceps
84
+ triceps
85
+ forearm
86
+ back-deltoids
87
+ front-deltoids
88
+
89
+ /* Abs */
90
+ abs
91
+ obliques
92
+
93
+ /* Legs */
94
+ adductor
95
+ hamstring
96
+ quadriceps
97
+ abductors
98
+ calves
99
+ gluteal
100
+
101
+ /* Head */
102
+ head
103
+ neck
104
+ ```
105
+
106
+ ## Modifying
107
+
108
+ The main SVG element has a class name `.rbh` which will allow you to manually change any styles necessary.
109
+
110
+ For example, you can add something like `.rhb polygon:hover { fill: #757782 !important; }` to your `.css` file to change the muscle color on mouse hover.
111
+
112
+ Otherwise, feel free to fork the repo and make any adjustments to your liking!
113
+
114
+ [license-image]: http://img.shields.io/npm/l/react-body-highlighter.svg
115
+ [license-url]: LICENSE
116
+ [downloads-image]: http://img.shields.io/npm/dm/react-body-highlighter.svg
117
+ [downloads-url]: http://npm-stat.com/charts.html?package=react-body-highlighter
118
+ [npm-version-image]: https://img.shields.io/npm/v/react-body-highlighter.svg
119
+ [npm-version-url]: https://www.npmjs.com/package/react-body-highlighter
@@ -0,0 +1,10 @@
1
+ import { Muscle } from '../component/metadata';
2
+ interface ISVGModelData {
3
+ muscle: Muscle;
4
+ svgPoints: string[];
5
+ }
6
+ export declare const femaleAnteriorData: ISVGModelData[];
7
+ export declare const femalePosteriorData: ISVGModelData[];
8
+ export declare const anteriorData: ISVGModelData[];
9
+ export declare const posteriorData: ISVGModelData[];
10
+ export {};
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ import { IModelProps } from './metadata';
3
+ declare const _default: React.NamedExoticComponent<IModelProps>;
4
+ /**
5
+ * Component which displays a model of a body. Accepts many optional props for manipulating functionality or visuals of the component.
6
+ *
7
+ * @param data Array containing exercise objects
8
+ * @param bodyColor Default color of body model (with no muscles worked)
9
+ * @param bodyType Body type to display (default `male` vs `female`)
10
+ * @param highlightedColors Array containing colors to display depending on frequency muscle is worked (where array index = frequency - 1)
11
+ * @param onClick Callback function when a muscle is clicked (returns back object with muscle-related data)
12
+ * @param svgStyle Style object that gets passed to SVG element
13
+ * @param style Style object that gets passed to SVG parent wrapper (div)
14
+ * @param type Denotes type of model (default `anterior` view vs `posterior` view)
15
+ *
16
+ * @component
17
+ * @example
18
+ * const data = [{ name: 'Bench Press', muscles: ['chest', 'triceps', 'front-deltoids'] }]
19
+ * return (
20
+ * <Model type="posterior" bodyType="female" data={data} />
21
+ * )
22
+ */
23
+ export default _default;
@@ -0,0 +1,60 @@
1
+ import { CSSProperties } from 'react';
2
+ export declare const MuscleType: {
3
+ readonly TRAPEZIUS: "trapezius";
4
+ readonly UPPER_BACK: "upper-back";
5
+ readonly LOWER_BACK: "lower-back";
6
+ readonly CHEST: "chest";
7
+ readonly BICEPS: "biceps";
8
+ readonly TRICEPS: "triceps";
9
+ readonly FOREARM: "forearm";
10
+ readonly BACK_DELTOIDS: "back-deltoids";
11
+ readonly FRONT_DELTOIDS: "front-deltoids";
12
+ readonly ABS: "abs";
13
+ readonly OBLIQUES: "obliques";
14
+ readonly ADDUCTOR: "adductor";
15
+ readonly ABDUCTORS: "abductors";
16
+ readonly HAMSTRING: "hamstring";
17
+ readonly QUADRICEPS: "quadriceps";
18
+ readonly CALVES: "calves";
19
+ readonly GLUTEAL: "gluteal";
20
+ readonly HEAD: "head";
21
+ readonly NECK: "neck";
22
+ readonly KNEES: "knees";
23
+ readonly LEFT_SOLEUS: "left-soleus";
24
+ readonly RIGHT_SOLEUS: "right-soleus";
25
+ };
26
+ export declare type Muscle = typeof MuscleType[keyof typeof MuscleType];
27
+ export declare const ModelType: {
28
+ readonly POSTERIOR: "posterior";
29
+ readonly ANTERIOR: "anterior";
30
+ };
31
+ declare type ModelType = typeof ModelType[keyof typeof ModelType];
32
+ export declare const BodyType: {
33
+ readonly MALE: "male";
34
+ readonly FEMALE: "female";
35
+ };
36
+ declare type BodyType = typeof BodyType[keyof typeof BodyType];
37
+ export interface IExerciseData {
38
+ name: string;
39
+ muscles: Muscle[];
40
+ frequency?: number;
41
+ }
42
+ export interface IMuscleData {
43
+ exercises: string[];
44
+ frequency: number;
45
+ }
46
+ export interface IMuscleStats {
47
+ muscle: Muscle;
48
+ data: IMuscleData;
49
+ }
50
+ export interface IModelProps {
51
+ bodyColor?: string;
52
+ bodyType?: BodyType;
53
+ data?: IExerciseData[];
54
+ highlightedColors?: string[];
55
+ onClick?: ((exercise: IMuscleStats) => void) | (() => void);
56
+ style?: CSSProperties;
57
+ svgStyle?: CSSProperties;
58
+ type?: ModelType;
59
+ }
60
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Muscle, IMuscleData } from '../component/metadata';
2
+ export declare const DEFAULT_MUSCLE_DATA: Record<Muscle, IMuscleData>;
3
+ export declare const DEFAULT_BODY_COLOR = "#B6BDC3";
4
+ export declare const DEFAULT_HIGHLIGHTED_COLORS: string[];
5
+ export declare const DEFAULT_MODEL_TYPE: "anterior";
6
+ export declare const DEFAULT_BODY_TYPE: "male";
@@ -0,0 +1,2 @@
1
+ export * from './component/metadata';
2
+ export { default } from './component/Model';
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./react-body-highlighter.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./react-body-highlighter.cjs.development.js')
8
+ }