@cntrl-site/sdk-nextjs 0.1.8 → 0.1.9

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.
Binary file
@@ -3,10 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Section = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const sdk_1 = require("@cntrl-site/sdk");
6
- const Section = ({ section, layouts, children }) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `section-${section.id}`, children: children }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
6
+ const Section = ({ section, layouts, children }) => {
7
+ const getSectionVisibilityStyles = () => {
8
+ return layouts
9
+ .sort((a, b) => a.startsWith - b.startsWith)
10
+ .reduce((acc, layout) => {
11
+ const isHidden = section.hidden[layout.id];
12
+ return `
13
+ ${acc}
14
+ ${(0, sdk_1.getLayoutMediaQuery)(layout.id, layouts)} {
15
+ .section-${section.id} {
16
+ display: ${isHidden ? 'none' : 'block'};
17
+ }
18
+ }`;
19
+ }, '');
20
+ };
21
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `section-${section.id}`, children: children }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
7
22
  ${(0, sdk_1.getLayoutStyles)(layouts, [section.height], ([height]) => (`
8
23
  .section-${section.id} {
9
24
  height: ${height * 100}vw;
25
+ position: relative;
10
26
  }`))}
27
+ ${getSectionVisibilityStyles()}
11
28
  ` })] }));
29
+ };
12
30
  exports.Section = Section;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.js",
@@ -1,5 +1,5 @@
1
1
  import { FC, ReactElement } from 'react';
2
- import { getLayoutStyles, TLayout, TArticleSection } from '@cntrl-site/sdk';
2
+ import { getLayoutMediaQuery, getLayoutStyles, TArticleSection, TLayout } from '@cntrl-site/sdk';
3
3
 
4
4
  type SectionChild = ReactElement<any, any>;
5
5
 
@@ -9,19 +9,38 @@ interface Props {
9
9
  children: SectionChild[];
10
10
  }
11
11
 
12
- export const Section: FC<Props> = ({ section, layouts, children }) => (
13
- <>
14
- <div className={`section-${section.id}`}>
15
- {children}
16
- </div>
17
- <style jsx>{`
12
+ export const Section: FC<Props> = ({ section, layouts, children }) => {
13
+ const getSectionVisibilityStyles = () => {
14
+ return layouts
15
+ .sort((a, b) => a.startsWith - b.startsWith)
16
+ .reduce((acc, layout) => {
17
+ const isHidden = section.hidden[layout.id];
18
+ return `
19
+ ${acc}
20
+ ${getLayoutMediaQuery(layout.id, layouts)} {
21
+ .section-${section.id} {
22
+ display: ${isHidden ? 'none': 'block'};
23
+ }
24
+ }`;
25
+ }, '');
26
+ };
27
+
28
+ return (
29
+ <>
30
+ <div className={`section-${section.id}`}>
31
+ {children}
32
+ </div>
33
+ <style jsx>{`
18
34
  ${
19
- getLayoutStyles(layouts, [section.height], ([height]) => (`
35
+ getLayoutStyles(layouts, [section.height], ([height]) => (`
20
36
  .section-${section.id} {
21
37
  height: ${height * 100}vw;
38
+ position: relative;
22
39
  }`
23
- ))
24
- }
40
+ ))
41
+ }
42
+ ${getSectionVisibilityStyles()}
25
43
  `}</style>
26
- </>
27
- );
44
+ </>
45
+ );
46
+ };