linear-react-components-ui 1.1.20-beta.3 → 1.1.20-beta.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.
@@ -7,8 +7,10 @@
7
7
  flex-direction: column;
8
8
  .wizard-progresbar {
9
9
  width: 100%;
10
- display: flex;
11
- align-items: center;
10
+ display: grid;
11
+ grid-auto-columns: 1fr;
12
+ grid-auto-flow: column;
13
+ justify-content: space-between;
12
14
  padding: 20px;
13
15
  margin-bottom: 20px;
14
16
  border-bottom: 2px solid $component-border-color;
@@ -22,12 +24,14 @@
22
24
  flex-direction: column;
23
25
  position: relative;
24
26
  flex: 1;
27
+ text-align: center;
25
28
  &:first-child {
26
29
  .step {
27
30
  align-self: flex-start;
28
31
  }
29
32
  .step-title {
30
33
  align-self: flex-start;
34
+ text-align: left;
31
35
  }
32
36
  &:before {
33
37
  right: auto;
@@ -40,6 +44,7 @@
40
44
  }
41
45
  .step-title {
42
46
  align-self: flex-end;
47
+ text-align: right;
43
48
  }
44
49
  &:after {
45
50
  left: auto;
@@ -52,7 +57,7 @@
52
57
  height: 2px;
53
58
  background-color: $component-border-color;
54
59
  top: 18px;
55
- width: calc(100% - 27px);
60
+ width: calc(100% - 25px);
56
61
  transition: all 0.2s ease-in-out;
57
62
  }
58
63
  &::after {
@@ -109,8 +114,6 @@
109
114
  > .step-title {
110
115
  max-width: 150px;
111
116
  overflow: hidden;
112
- text-overflow: ellipsis;
113
- text-wrap: nowrap;
114
117
  margin-top: 6px;
115
118
  font-weight: 500;
116
119
  color: $font-color-soft;
@@ -75,7 +75,7 @@ interface WizardComponentProps extends Omit<IFormProps, 'content'> {
75
75
  showProgressbar?: boolean;
76
76
  title?: string;
77
77
  handlerClose?: () => void;
78
- controls: Omit<UseWizardReturn, 'controls'>;
78
+ controls: WizardControls;
79
79
  }
80
80
  interface WizardStepComponentProps {
81
81
  children: React.ReactNode;
@@ -84,6 +84,7 @@ interface WizardStepComponentProps {
84
84
  customStyle?: CSSProperties;
85
85
  }
86
86
  interface WizardControls extends Omit<UseWizardReturn, 'controls'> {
87
+ setTotalSteps: Dispatch<React.SetStateAction<number>>;
87
88
  }
88
89
  interface UseWizardReturn {
89
90
  changeStep: (nextStep: number) => void;
@@ -91,11 +92,8 @@ interface UseWizardReturn {
91
92
  hasNextStep: boolean;
92
93
  previousStep: () => void;
93
94
  hasPreviousStep: boolean;
94
- steps: ReactNode[];
95
- currentStep: ReactElement;
96
- currentStepIndex: number;
95
+ currentStep: number;
97
96
  totalSteps: number;
98
- setSteps: Dispatch<React.SetStateAction<ReactNode[]>>;
99
97
  controls: WizardControls;
100
98
  }
101
99
 
@@ -43,22 +43,32 @@ function Wizard(_ref) {
43
43
  } = _ref,
44
44
  dialogProps = _objectWithoutProperties(_ref, _excluded);
45
45
  const {
46
- setSteps,
47
- currentStep
46
+ currentStep,
47
+ setTotalSteps
48
48
  } = controls;
49
+ const steps = _react.default.Children.toArray(children);
50
+ const stepsTitle = steps.map((step, index) => {
51
+ return {
52
+ title: String(step.props.title),
53
+ number: index + 1,
54
+ completed: index < currentStep - 1 && index !== currentStep
55
+ };
56
+ });
57
+ const currentStepElement = steps[currentStep - 1];
49
58
  if (!controls || _lodash.default.isEmpty(controls)) throw new Error('Wizard must be have controls by using useWizard hook or creating manually.');
50
- const propSteps = _react.default.Children.toArray(children);
51
59
  (0, _react.useEffect)(() => {
52
- setSteps(propSteps);
53
- }, []);
60
+ setTotalSteps(steps.length);
61
+ }, [steps.length]);
54
62
  return /*#__PURE__*/_react.default.createElement(WizardContext.Provider, {
55
63
  value: controls
56
64
  }, /*#__PURE__*/_react.default.createElement(_form.default, _extends({
57
65
  className: "wizard-dialog",
58
66
  wrapperClassName: "wizard-wrapper",
59
67
  contentClassName: "wizard-content"
60
- }, dialogProps), showProgressbar && /*#__PURE__*/_react.default.createElement(_progressbar.Progressbar, null), /*#__PURE__*/_react.default.createElement("div", {
68
+ }, dialogProps), showProgressbar && /*#__PURE__*/_react.default.createElement(_progressbar.Progressbar, {
69
+ stepsTitle: stepsTitle
70
+ }), /*#__PURE__*/_react.default.createElement("div", {
61
71
  className: "wizard-body"
62
- }, currentStep)));
72
+ }, currentStepElement)));
63
73
  }
64
74
  var _default = exports.default = Wizard;
@@ -1,7 +1,12 @@
1
1
  import { CSSProperties } from 'react';
2
2
 
3
- declare function Progressbar({ customClass, customStyle }: Readonly<{
3
+ declare function Progressbar({ customClass, customStyle, stepsTitle }: Readonly<{
4
4
  customClass?: string;
5
+ stepsTitle: {
6
+ title: string;
7
+ number: number;
8
+ completed: boolean;
9
+ }[];
5
10
  customStyle?: CSSProperties;
6
11
  }>): JSX.Element;
7
12
 
@@ -10,20 +10,14 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
10
10
  function Progressbar(_ref) {
11
11
  let {
12
12
  customClass,
13
- customStyle
13
+ customStyle,
14
+ stepsTitle
14
15
  } = _ref;
15
16
  const context = (0, _.useWizardContext)();
16
17
  if (!context) throw new Error('WizardProgressbar must be used within a Wizard component');
17
18
  const {
18
- steps,
19
- currentStepIndex
19
+ currentStep
20
20
  } = context;
21
- const stepsElements = _react.default.Children.toArray(steps);
22
- const stepsTitle = stepsElements.map((step, index) => ({
23
- title: step.props.title,
24
- number: index + 1,
25
- completed: index < currentStepIndex - 1 && index !== currentStepIndex
26
- }));
27
21
  return /*#__PURE__*/_react.default.createElement("div", {
28
22
  className: "wizard-progresbar ".concat(customClass),
29
23
  style: customStyle
@@ -31,7 +25,7 @@ function Progressbar(_ref) {
31
25
  key: step.number,
32
26
  className: "title",
33
27
  "data-completed": step.completed,
34
- "data-disabled": step.number > currentStepIndex
28
+ "data-disabled": step.number > currentStep
35
29
  }, /*#__PURE__*/_react.default.createElement("div", {
36
30
  className: "step"
37
31
  }, /*#__PURE__*/_react.default.createElement("span", {
@@ -8,15 +8,12 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
9
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
10
  const useWizard = () => {
11
- var _ref;
12
- const [steps, setSteps] = (0, _react.useState)([]);
13
- const totalSteps = steps.length;
14
- const [step, setStep] = _react.default.useState(1);
15
- const currentStep = (_ref = steps[step - 1]) !== null && _ref !== void 0 ? _ref : null;
16
- const hasNextStep = step < totalSteps;
17
- const hasPreviousStep = step > 1;
11
+ const [totalSteps, setTotalSteps] = (0, _react.useState)(0);
12
+ const [currentStep, setCurrentStep] = _react.default.useState(1);
13
+ const hasNextStep = currentStep < totalSteps;
14
+ const hasPreviousStep = currentStep > 1;
18
15
  const changeStep = nextStep => {
19
- setStep(state => state + nextStep);
16
+ setCurrentStep(state => state + nextStep);
20
17
  };
21
18
  const nextStep = () => {
22
19
  if (hasNextStep) {
@@ -34,10 +31,7 @@ const useWizard = () => {
34
31
  hasNextStep,
35
32
  previousStep,
36
33
  hasPreviousStep,
37
- steps,
38
34
  currentStep,
39
- currentStepIndex: step,
40
- setSteps,
41
35
  totalSteps,
42
36
  controls: {
43
37
  changeStep,
@@ -45,11 +39,9 @@ const useWizard = () => {
45
39
  hasNextStep,
46
40
  previousStep,
47
41
  hasPreviousStep,
48
- steps,
49
42
  currentStep,
50
- currentStepIndex: step,
51
- setSteps,
52
- totalSteps
43
+ totalSteps,
44
+ setTotalSteps
53
45
  }
54
46
  };
55
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linear-react-components-ui",
3
- "version": "1.1.20-beta.3",
3
+ "version": "1.1.20-beta.5",
4
4
  "description": "Linear Sistemas ReactJs Components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.cjs",