@oneblink/apps-react 0.5.7-beta.1 → 0.5.8-beta.1
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/dist/OneBlinkFormBase.js +6 -3
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/form-elements/FormElementSection.js +4 -0
- package/dist/form-elements/FormElementSection.js.map +1 -1
- package/dist/hooks/attachments/useAttachment.js +39 -8
- package/dist/hooks/attachments/useAttachment.js.map +1 -1
- package/dist/hooks/attachments/useAttachmentBlobs.d.ts +19 -0
- package/dist/hooks/attachments/useAttachmentBlobs.js +24 -0
- package/dist/hooks/attachments/useAttachmentBlobs.js.map +1 -0
- package/dist/hooks/usePages.js +16 -5
- package/dist/hooks/usePages.js.map +1 -1
- package/dist/styles/renderer.scss +0 -167
- package/dist/styles/steps.scss +181 -0
- package/dist/styles.css +150 -140
- package/dist/styles.css.map +1 -1
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usePages.js","sourceRoot":"","sources":["../../src/hooks/usePages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,gBAAgB,MAAM,+BAA+B,CAAA;AAM5D,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,KAAK,EACL,sBAAsB,EACtB,8BAA8B,GAK/B;IACC,MAAM,+BAA+B,GAAG,KAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAA;IAC1E,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAW,EAAE,CAAC,CAAA;IAExE,MAAM,CAAC,mBAAmB,EAAE,AAAD,EAAG,oBAAoB,EAAE,qBAAqB,CAAC,GACxE,eAAe,CAAC,KAAK,CAAC,CAAA;IAEx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AAM;YACL,yCAAyC;YACzC,gBAAgB,CAAC,eAAe,EAAE,CAAA;SACnC;IACH,CAAC,EAAE,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC,CAAA;IAExC,MAAM,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;IACxC,MAAM,eAAe,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC7D,MAAM,iBAAiB,GACrB,eAAe,IAAI,eAAe,CAAC,EAAE,KAAK,aAAa,CAAA;IACzD,MAAM,kBAAkB,GACtB,gBAAgB,IAAI,gBAAgB,CAAC,EAAE,KAAK,aAAa,CAAA;IAC3D,MAAM,4BAA4B,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAA;IAEvE,uCAAuC;IACvC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,OAAO,GAAG,EAAE;YACV,gBAAgB,CAAC,eAAe,EAAE,CAAA;QACpC,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,YAAY;QACZ,kBAAkB;QAClB,iBAAiB;QACjB,4BAA4B;QAC5B,sBAAsB;QACtB,mBAAmB;QACnB,qBAAqB;QACrB,gBAAgB;QAChB,WAAW;QACX,iBAAiB;QACjB,qBAAqB;QACrB,SAAS;QACT,gBAAgB;QAChB,YAAY;QACZ,+BAA+B;KAChC,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport * as React from 'react'\n\nimport useBooleanState from '../hooks/useBooleanState'\nimport { checkSectionValidity } from '../services/form-validation'\nimport scrollingService from '../services/scrolling-service'\nimport {\n FormElementsConditionallyShown,\n FormElementsValidation,\n} from '../types/form'\n\nexport default function usePages({\n pages,\n formElementsValidation,\n formElementsConditionallyShown,\n}: {\n pages: FormTypes.PageElement[]\n formElementsValidation: FormElementsValidation | undefined\n formElementsConditionallyShown: FormElementsConditionallyShown\n}) {\n const scrollToTopOfPageHTMLElementRef = React.useRef<HTMLDivElement>(null)\n const [visitedPageIds, setVisitedPageIds] = React.useState<string[]>([])\n\n const [isStepsHeaderActive, , closeStepsNavigation, toggleStepsNavigation] =\n useBooleanState(false)\n\n const visiblePages = React.useMemo<FormTypes.PageElement[]>(() => {\n return pages.filter((pageElement) => {\n return !formElementsConditionallyShown?.[pageElement.id]?.isHidden\n })\n }, [formElementsConditionallyShown, pages])\n\n const [currentPageId, setCurrentPageId] = React.useState(visiblePages[0].id)\n\n const currentPage = React.useMemo(() => {\n const currentPageById = visiblePages.find((pageElement) => {\n return pageElement.id === currentPageId\n })\n if (currentPageById) {\n return currentPageById\n } else {\n return visiblePages[0]\n }\n }, [currentPageId, visiblePages])\n\n const currentPageIndex = React.useMemo(\n () => visiblePages.indexOf(currentPage),\n [currentPage, visiblePages],\n )\n\n const currentPageNumber = React.useMemo(() => {\n if (currentPage) {\n return visiblePages.indexOf(currentPage) + 1\n }\n }, [currentPage, visiblePages])\n\n const isShowingMultiplePages = visiblePages.length > 1\n\n const setPageId = React.useCallback(\n (pageId: string) => {\n setVisitedPageIds((currentVisitedPageIds) => {\n if (currentVisitedPageIds.includes(currentPageId)) {\n return currentVisitedPageIds\n } else {\n return [...currentVisitedPageIds, currentPageId]\n }\n })\n setCurrentPageId(pageId)\n closeStepsNavigation()\n\n const scrollToTopOfPageHTMLElement =\n scrollToTopOfPageHTMLElementRef.current\n if (isShowingMultiplePages && scrollToTopOfPageHTMLElement) {\n window.requestAnimationFrame(() => {\n scrollToTopOfPageHTMLElement.scrollIntoView({\n block: 'start',\n behavior: 'smooth',\n })\n })\n }\n },\n [closeStepsNavigation, currentPageId, isShowingMultiplePages],\n )\n\n const goToNextPage = React.useCallback(() => {\n for (let i = 0; i < visiblePages.length; i++) {\n const page = visiblePages[i]\n if (page.id === currentPageId) {\n const nextVisiblePage = visiblePages[i + 1]\n if (nextVisiblePage) {\n setPageId(nextVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const goToPreviousPage = React.useCallback(() => {\n for (let i = visiblePages.length - 1; i > -1; i--) {\n const page = visiblePages[i]\n if (page && page.id === currentPageId) {\n const previousVisiblePage = visiblePages[i - 1]\n if (previousVisiblePage) {\n setPageId(previousVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const checkDisplayPageError = React.useCallback(\n (page: FormTypes.PageElement) => {\n // If we have not visited the page yet, we will not display errors\n if (!visitedPageIds.includes(page.id)) {\n return false\n }\n\n return checkSectionValidity(page, formElementsValidation)\n },\n [formElementsValidation, visitedPageIds],\n )\n\n React.useEffect(() => {\n if (isStepsHeaderActive) {\n scrollingService.disableScrolling()\n\n const activeStepElement = document.getElementById(\n `steps-navigation-step-${currentPageId}`,\n )\n\n if (activeStepElement) {\n activeStepElement.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n })\n }\n } else {\n // Re-enable scroll on body when inactive\n scrollingService.enableScrolling()\n }\n }, [currentPageId, isStepsHeaderActive])\n\n const firstVisiblePage = visiblePages[0]\n const lastVisiblePage = visiblePages[visiblePages.length - 1]\n const isLastVisiblePage =\n lastVisiblePage && lastVisiblePage.id === currentPageId\n const isFirstVisiblePage =\n firstVisiblePage && firstVisiblePage.id === currentPageId\n const isDisplayingCurrentPageError = checkDisplayPageError(currentPage)\n\n // Clean up when form is navigated away\n React.useEffect(() => {\n return () => {\n scrollingService.enableScrolling()\n }\n }, [])\n\n return {\n visiblePages,\n isFirstVisiblePage,\n isLastVisiblePage,\n isDisplayingCurrentPageError,\n isShowingMultiplePages,\n isStepsHeaderActive,\n toggleStepsNavigation,\n currentPageIndex,\n currentPage,\n currentPageNumber,\n checkDisplayPageError,\n setPageId,\n goToPreviousPage,\n goToNextPage,\n scrollToTopOfPageHTMLElementRef,\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"usePages.js","sourceRoot":"","sources":["../../src/hooks/usePages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;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,CAAA;IAC3D,MAAM,4BAA4B,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAA;IAEvE,uCAAuC;IACvC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,OAAO,GAAG,EAAE;YACV,gBAAgB,CAAC,eAAe,EAAE,CAAA;QACpC,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,YAAY;QACZ,kBAAkB;QAClB,iBAAiB;QACjB,4BAA4B;QAC5B,sBAAsB;QACtB,mBAAmB;QACnB,qBAAqB;QACrB,gBAAgB;QAChB,WAAW;QACX,iBAAiB;QACjB,qBAAqB;QACrB,SAAS;QACT,gBAAgB;QAChB,YAAY;QACZ,+BAA+B;KAChC,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport * as React from 'react'\n\nimport useBooleanState from '../hooks/useBooleanState'\nimport { checkSectionValidity } from '../services/form-validation'\nimport scrollingService from '../services/scrolling-service'\nimport {\n FormElementsConditionallyShown,\n FormElementsValidation,\n} from '../types/form'\n\nexport default function usePages({\n pages,\n formElementsValidation,\n formElementsConditionallyShown,\n}: {\n pages: FormTypes.PageElement[]\n formElementsValidation: FormElementsValidation | undefined\n formElementsConditionallyShown: FormElementsConditionallyShown\n}) {\n const scrollToTopOfPageHTMLElementRef = React.useRef<HTMLDivElement>(null)\n const [visitedPageIds, setVisitedPageIds] = React.useState<string[]>([])\n\n const [isStepsHeaderActive, , closeStepsNavigation, toggleStepsNavigation] =\n useBooleanState(false)\n\n const visiblePages = React.useMemo<FormTypes.PageElement[]>(() => {\n return pages.filter((pageElement) => {\n return !formElementsConditionallyShown?.[pageElement.id]?.isHidden\n })\n }, [formElementsConditionallyShown, pages])\n\n const [currentPageId, setCurrentPageId] = React.useState(visiblePages[0].id)\n\n const currentPage = React.useMemo(() => {\n const currentPageById = visiblePages.find((pageElement) => {\n return pageElement.id === currentPageId\n })\n if (currentPageById) {\n return currentPageById\n } else {\n return visiblePages[0]\n }\n }, [currentPageId, visiblePages])\n\n const currentPageIndex = React.useMemo(\n () => visiblePages.indexOf(currentPage),\n [currentPage, visiblePages],\n )\n\n const currentPageNumber = React.useMemo(() => {\n if (currentPage) {\n return visiblePages.indexOf(currentPage) + 1\n }\n }, [currentPage, visiblePages])\n\n const isShowingMultiplePages = visiblePages.length > 1\n\n const setPageId = React.useCallback(\n (pageId: string) => {\n setVisitedPageIds((currentVisitedPageIds) => {\n if (currentVisitedPageIds.includes(currentPageId)) {\n return currentVisitedPageIds\n } else {\n return [...currentVisitedPageIds, currentPageId]\n }\n })\n setCurrentPageId(pageId)\n closeStepsNavigation()\n\n const scrollToTopOfPageHTMLElement =\n scrollToTopOfPageHTMLElementRef.current\n if (isShowingMultiplePages && scrollToTopOfPageHTMLElement) {\n if (scrollToTopOfPageHTMLElement) {\n window.requestAnimationFrame(() => {\n scrollToTopOfPageHTMLElement.scrollIntoView({\n block: 'start',\n behavior: 'smooth',\n })\n })\n }\n const stepItemHTMLElement = document.getElementById(\n `steps-navigation-step-${pageId}`,\n )\n if (stepItemHTMLElement) {\n window.requestAnimationFrame(() => {\n stepItemHTMLElement.scrollIntoView({\n block: 'start',\n behavior: 'smooth',\n })\n })\n }\n }\n },\n [closeStepsNavigation, currentPageId, isShowingMultiplePages],\n )\n\n const goToNextPage = React.useCallback(() => {\n for (let i = 0; i < visiblePages.length; i++) {\n const page = visiblePages[i]\n if (page.id === currentPageId) {\n const nextVisiblePage = visiblePages[i + 1]\n if (nextVisiblePage) {\n setPageId(nextVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const goToPreviousPage = React.useCallback(() => {\n for (let i = visiblePages.length - 1; i > -1; i--) {\n const page = visiblePages[i]\n if (page && page.id === currentPageId) {\n const previousVisiblePage = visiblePages[i - 1]\n if (previousVisiblePage) {\n setPageId(previousVisiblePage.id)\n }\n break\n }\n }\n }, [currentPageId, setPageId, visiblePages])\n\n const checkDisplayPageError = React.useCallback(\n (page: FormTypes.PageElement) => {\n // If we have not visited the page yet, we will not display errors\n if (!visitedPageIds.includes(page.id)) {\n return false\n }\n\n return checkSectionValidity(page, formElementsValidation)\n },\n [formElementsValidation, visitedPageIds],\n )\n\n React.useEffect(() => {\n if (isStepsHeaderActive) {\n scrollingService.disableScrolling()\n\n const activeStepElement = document.getElementById(\n `steps-navigation-step-${currentPageId}`,\n )\n\n if (activeStepElement) {\n activeStepElement.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n })\n }\n } else {\n // Re-enable scroll on body when inactive\n scrollingService.enableScrolling()\n }\n }, [currentPageId, isStepsHeaderActive])\n\n const firstVisiblePage = visiblePages[0]\n const lastVisiblePage = visiblePages[visiblePages.length - 1]\n const isLastVisiblePage =\n lastVisiblePage && lastVisiblePage.id === currentPageId\n const isFirstVisiblePage =\n firstVisiblePage && firstVisiblePage.id === currentPageId\n const isDisplayingCurrentPageError = checkDisplayPageError(currentPage)\n\n // Clean up when form is navigated away\n React.useEffect(() => {\n return () => {\n scrollingService.enableScrolling()\n }\n }, [])\n\n return {\n visiblePages,\n isFirstVisiblePage,\n isLastVisiblePage,\n isDisplayingCurrentPageError,\n isShowingMultiplePages,\n isStepsHeaderActive,\n toggleStepsNavigation,\n currentPageIndex,\n currentPage,\n currentPageNumber,\n checkDisplayPageError,\n setPageId,\n goToPreviousPage,\n goToNextPage,\n scrollToTopOfPageHTMLElementRef,\n }\n}\n"]}
|
@@ -25,69 +25,9 @@
|
|
25
25
|
margin-left: $size-8;
|
26
26
|
}
|
27
27
|
|
28
|
-
.ob-steps-navigation__header {
|
29
|
-
display: none;
|
30
|
-
}
|
31
|
-
|
32
28
|
.ob-form-container {
|
33
29
|
position: relative;
|
34
30
|
|
35
|
-
.steps {
|
36
|
-
&.is-small {
|
37
|
-
font-size: $size-6;
|
38
|
-
}
|
39
|
-
|
40
|
-
.step-item {
|
41
|
-
font-size: $size-7;
|
42
|
-
cursor: pointer;
|
43
|
-
|
44
|
-
&:focus {
|
45
|
-
outline: none;
|
46
|
-
}
|
47
|
-
|
48
|
-
&.is-disabled {
|
49
|
-
.step-marker {
|
50
|
-
opacity: 0.2;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
&.is-error {
|
55
|
-
.step-marker {
|
56
|
-
background-color: transparent;
|
57
|
-
border-color: transparent;
|
58
|
-
|
59
|
-
.material-icons {
|
60
|
-
background-color: $white;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
.steps-content {
|
67
|
-
width: 100%;
|
68
|
-
|
69
|
-
.step-content {
|
70
|
-
width: 100%;
|
71
|
-
|
72
|
-
&.is-invisible {
|
73
|
-
position: fixed;
|
74
|
-
top: 0;
|
75
|
-
bottom: 0;
|
76
|
-
overflow: hidden;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
&.is-single-step {
|
81
|
-
margin-top: 0;
|
82
|
-
margin-bottom: 0;
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
.step-progress-mobile {
|
87
|
-
display: none;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
31
|
.field {
|
92
32
|
width: 100%;
|
93
33
|
|
@@ -105,19 +45,6 @@
|
|
105
45
|
flex: 1;
|
106
46
|
}
|
107
47
|
|
108
|
-
.steps-header-active-page-icon {
|
109
|
-
color: $primary;
|
110
|
-
border: 0.2em solid $primary;
|
111
|
-
border-radius: 50%;
|
112
|
-
min-height: $size-4;
|
113
|
-
min-width: $size-4;
|
114
|
-
font-size: $size-7;
|
115
|
-
margin-right: $size-8;
|
116
|
-
display: inline-flex;
|
117
|
-
justify-content: center;
|
118
|
-
align-items: center;
|
119
|
-
}
|
120
|
-
|
121
48
|
@media only screen and (max-width: $mobile) {
|
122
49
|
.ob-form-container {
|
123
50
|
.ob-button {
|
@@ -137,100 +64,6 @@
|
|
137
64
|
}
|
138
65
|
}
|
139
66
|
|
140
|
-
@media only screen and (max-width: $tablet) {
|
141
|
-
.ob-steps-navigation {
|
142
|
-
position: relative;
|
143
|
-
}
|
144
|
-
|
145
|
-
.ob-steps-navigation__header {
|
146
|
-
z-index: 30;
|
147
|
-
height: $size-1;
|
148
|
-
display: flex;
|
149
|
-
align-items: center;
|
150
|
-
background-color: $white-ter;
|
151
|
-
box-shadow: $elevation-2;
|
152
|
-
-webkit-transition: box-shadow 0.2s ease;
|
153
|
-
-moz-transition: box-shadow 0.2s ease;
|
154
|
-
-o-transition: box-shadow 0.2s ease;
|
155
|
-
transition: box-shadow 0.2s ease;
|
156
|
-
|
157
|
-
&:focus {
|
158
|
-
outline: none;
|
159
|
-
}
|
160
|
-
|
161
|
-
&.is-active {
|
162
|
-
box-shadow: none;
|
163
|
-
|
164
|
-
& > .dropdown.icon {
|
165
|
-
transform: rotate(180deg);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
|
169
|
-
.steps-header-active-page {
|
170
|
-
flex: 1;
|
171
|
-
min-width: 0;
|
172
|
-
display: flex;
|
173
|
-
justify-content: center;
|
174
|
-
align-items: center;
|
175
|
-
|
176
|
-
.icon {
|
177
|
-
margin-right: $size-8;
|
178
|
-
}
|
179
|
-
}
|
180
|
-
|
181
|
-
.steps-header-active-page-label {
|
182
|
-
white-space: nowrap;
|
183
|
-
overflow: hidden;
|
184
|
-
text-overflow: ellipsis;
|
185
|
-
}
|
186
|
-
|
187
|
-
.icon {
|
188
|
-
padding: $size-7;
|
189
|
-
line-height: 1;
|
190
|
-
-webkit-transition: transform 0.2s linear;
|
191
|
-
-moz-transition: transform 0.2s linear;
|
192
|
-
-o-transition: transform 0.2s linear;
|
193
|
-
transition: transform 0.2s linear;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
.ob-steps-navigation__steps {
|
198
|
-
z-index: 30;
|
199
|
-
position: absolute;
|
200
|
-
top: $size-1;
|
201
|
-
right: 0;
|
202
|
-
left: 0;
|
203
|
-
background-color: $white;
|
204
|
-
box-shadow: none;
|
205
|
-
max-height: 0;
|
206
|
-
overflow-y: auto;
|
207
|
-
-webkit-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
208
|
-
-moz-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
209
|
-
-o-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
210
|
-
transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
211
|
-
|
212
|
-
&.is-active {
|
213
|
-
box-shadow: $elevation-3;
|
214
|
-
max-height: 40vh;
|
215
|
-
}
|
216
|
-
|
217
|
-
.steps {
|
218
|
-
padding: $size-4;
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
.ob-steps-navigation__background.is-active {
|
223
|
-
background-color: $black;
|
224
|
-
opacity: 0.2;
|
225
|
-
z-index: 20;
|
226
|
-
position: absolute;
|
227
|
-
top: 0;
|
228
|
-
bottom: 0;
|
229
|
-
right: 0;
|
230
|
-
left: 0;
|
231
|
-
}
|
232
|
-
}
|
233
|
-
|
234
67
|
.ob-hint-tooltip {
|
235
68
|
max-width: 400px;
|
236
69
|
}
|
package/dist/styles/steps.scss
CHANGED
@@ -1,3 +1,92 @@
|
|
1
|
+
.ob-steps-navigation__header {
|
2
|
+
display: none;
|
3
|
+
}
|
4
|
+
|
5
|
+
.ob-form-container {
|
6
|
+
.steps {
|
7
|
+
&.is-small {
|
8
|
+
font-size: $size-6;
|
9
|
+
}
|
10
|
+
|
11
|
+
.step-item {
|
12
|
+
font-size: $size-7;
|
13
|
+
cursor: pointer;
|
14
|
+
|
15
|
+
&:focus {
|
16
|
+
outline: none;
|
17
|
+
}
|
18
|
+
|
19
|
+
&.is-disabled {
|
20
|
+
.step-marker {
|
21
|
+
opacity: 0.2;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
&.is-error {
|
26
|
+
.step-marker {
|
27
|
+
background-color: transparent;
|
28
|
+
border-color: transparent;
|
29
|
+
|
30
|
+
.material-icons {
|
31
|
+
background-color: $white;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
.steps-content {
|
38
|
+
width: 100%;
|
39
|
+
|
40
|
+
.step-content {
|
41
|
+
width: 100%;
|
42
|
+
|
43
|
+
&.is-invisible {
|
44
|
+
position: fixed;
|
45
|
+
top: 0;
|
46
|
+
bottom: 0;
|
47
|
+
overflow: hidden;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
&.is-single-step {
|
52
|
+
margin-top: 0;
|
53
|
+
margin-bottom: 0;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
.step-progress-mobile {
|
58
|
+
display: none;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
.steps-header-active-page-icon {
|
64
|
+
color: $primary;
|
65
|
+
border: 0.2em solid $primary;
|
66
|
+
border-radius: 50%;
|
67
|
+
min-height: $size-4;
|
68
|
+
min-width: $size-4;
|
69
|
+
font-size: $size-7;
|
70
|
+
margin-right: $size-8;
|
71
|
+
display: inline-flex;
|
72
|
+
justify-content: center;
|
73
|
+
align-items: center;
|
74
|
+
}
|
75
|
+
|
76
|
+
@media only screen and (min-width: $tablet) {
|
77
|
+
.ob-steps-navigation__steps {
|
78
|
+
.steps.is-small {
|
79
|
+
flex-wrap: nowrap;
|
80
|
+
overflow-x: auto;
|
81
|
+
|
82
|
+
.step-item {
|
83
|
+
min-width: 100px;
|
84
|
+
margin: $size-8;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
1
90
|
@media only screen and (max-width: $tablet) {
|
2
91
|
.steps.is-horizontal-tablet {
|
3
92
|
flex-direction: column;
|
@@ -44,4 +133,96 @@
|
|
44
133
|
}
|
45
134
|
}
|
46
135
|
}
|
136
|
+
|
137
|
+
.ob-steps-navigation {
|
138
|
+
position: relative;
|
139
|
+
}
|
140
|
+
|
141
|
+
.ob-steps-navigation__header {
|
142
|
+
z-index: 30;
|
143
|
+
height: $size-1;
|
144
|
+
display: flex;
|
145
|
+
align-items: center;
|
146
|
+
background-color: $white-ter;
|
147
|
+
box-shadow: $elevation-2;
|
148
|
+
-webkit-transition: box-shadow 0.2s ease;
|
149
|
+
-moz-transition: box-shadow 0.2s ease;
|
150
|
+
-o-transition: box-shadow 0.2s ease;
|
151
|
+
transition: box-shadow 0.2s ease;
|
152
|
+
|
153
|
+
&:focus {
|
154
|
+
outline: none;
|
155
|
+
}
|
156
|
+
|
157
|
+
&.is-active {
|
158
|
+
box-shadow: none;
|
159
|
+
|
160
|
+
& > .dropdown.icon {
|
161
|
+
transform: rotate(180deg);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
.steps-header-active-page {
|
166
|
+
flex: 1;
|
167
|
+
min-width: 0;
|
168
|
+
display: flex;
|
169
|
+
justify-content: center;
|
170
|
+
align-items: center;
|
171
|
+
|
172
|
+
.icon {
|
173
|
+
margin-right: $size-8;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
.steps-header-active-page-label {
|
178
|
+
white-space: nowrap;
|
179
|
+
overflow: hidden;
|
180
|
+
text-overflow: ellipsis;
|
181
|
+
}
|
182
|
+
|
183
|
+
.icon {
|
184
|
+
padding: $size-7;
|
185
|
+
line-height: 1;
|
186
|
+
-webkit-transition: transform 0.2s linear;
|
187
|
+
-moz-transition: transform 0.2s linear;
|
188
|
+
-o-transition: transform 0.2s linear;
|
189
|
+
transition: transform 0.2s linear;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
.ob-steps-navigation__steps {
|
194
|
+
z-index: 30;
|
195
|
+
position: absolute;
|
196
|
+
top: $size-1;
|
197
|
+
right: 0;
|
198
|
+
left: 0;
|
199
|
+
background-color: $white;
|
200
|
+
box-shadow: none;
|
201
|
+
max-height: 0;
|
202
|
+
overflow-y: auto;
|
203
|
+
-webkit-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
204
|
+
-moz-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
205
|
+
-o-transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
206
|
+
transition: box-shadow 0.2s ease, max-height 0.2s ease;
|
207
|
+
|
208
|
+
&.is-active {
|
209
|
+
box-shadow: $elevation-3;
|
210
|
+
max-height: 40vh;
|
211
|
+
}
|
212
|
+
|
213
|
+
.steps {
|
214
|
+
padding: $size-4;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
.ob-steps-navigation__background.is-active {
|
219
|
+
background-color: $black;
|
220
|
+
opacity: 0.2;
|
221
|
+
z-index: 20;
|
222
|
+
position: absolute;
|
223
|
+
top: 0;
|
224
|
+
bottom: 0;
|
225
|
+
right: 0;
|
226
|
+
left: 0;
|
227
|
+
}
|
47
228
|
}
|