create-sitecore-jss 20.0.0-canary.78

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 (166) hide show
  1. package/LICENSE.MD +202 -0
  2. package/dist/InitializerFactory.js +49 -0
  3. package/dist/common/Initializer.js +2 -0
  4. package/dist/common/args/base.js +2 -0
  5. package/dist/common/args/styleguide.js +2 -0
  6. package/dist/common/prompts/base.js +40 -0
  7. package/dist/common/prompts/styleguide.js +28 -0
  8. package/dist/common/steps/index.js +13 -0
  9. package/dist/common/steps/install.js +46 -0
  10. package/dist/common/steps/next.js +60 -0
  11. package/dist/common/steps/transform.js +185 -0
  12. package/dist/common/utils/cmd.js +39 -0
  13. package/dist/common/utils/helpers.js +92 -0
  14. package/dist/index.js +91 -0
  15. package/dist/init-runner.js +50 -0
  16. package/dist/initializers/nextjs/args.js +2 -0
  17. package/dist/initializers/nextjs/index.js +65 -0
  18. package/dist/initializers/nextjs/prompts.js +19 -0
  19. package/dist/initializers/nextjs/remove-dev-dependencies.js +24 -0
  20. package/dist/initializers/nextjs-styleguide/index.js +49 -0
  21. package/dist/templates/nextjs/.env +49 -0
  22. package/dist/templates/nextjs/.eslintrc +25 -0
  23. package/dist/templates/nextjs/.gitattributes +11 -0
  24. package/dist/templates/nextjs/.gitignore +33 -0
  25. package/dist/templates/nextjs/.graphql-let.yml +10 -0
  26. package/dist/templates/nextjs/.prettierignore +1 -0
  27. package/dist/templates/nextjs/.prettierrc +8 -0
  28. package/dist/templates/nextjs/LICENSE.txt +202 -0
  29. package/dist/templates/nextjs/README.md +3 -0
  30. package/dist/templates/nextjs/next-env.d.ts +6 -0
  31. package/dist/templates/nextjs/next.config.js +56 -0
  32. package/dist/templates/nextjs/package.json +88 -0
  33. package/dist/templates/nextjs/public/favicon.ico +0 -0
  34. package/dist/templates/nextjs/public/sc_logo.svg +20 -0
  35. package/dist/templates/nextjs/scripts/bootstrap.ts +40 -0
  36. package/dist/templates/nextjs/scripts/fetch-graphql-introspection-data.ts +49 -0
  37. package/dist/templates/nextjs/scripts/generate-component-factory.ts +95 -0
  38. package/dist/templates/nextjs/scripts/generate-config.ts +85 -0
  39. package/dist/templates/nextjs/scripts/generate-plugins.ts +103 -0
  40. package/dist/templates/nextjs/scripts/scaffold-component.ts +89 -0
  41. package/dist/templates/nextjs/scripts/templates/component-factory.ts +119 -0
  42. package/dist/templates/nextjs/scripts/templates/component-src.ts +27 -0
  43. package/dist/templates/nextjs/scripts/utils.ts +59 -0
  44. package/dist/templates/nextjs/sitecore/config/{{appName}}.config +151 -0
  45. package/dist/templates/nextjs/src/Layout.tsx +53 -0
  46. package/dist/templates/nextjs/src/Navigation.tsx +27 -0
  47. package/dist/templates/nextjs/src/NotFound.tsx +19 -0
  48. package/dist/templates/nextjs/src/assets/app.css +28 -0
  49. package/dist/templates/nextjs/src/components/ContentBlock.tsx +24 -0
  50. package/dist/templates/nextjs/src/lib/component-props/index.ts +23 -0
  51. package/dist/templates/nextjs/src/lib/data-fetcher.ts +16 -0
  52. package/dist/templates/nextjs/src/lib/dictionary-service-factory.ts +30 -0
  53. package/dist/templates/nextjs/src/lib/layout-service-factory.ts +25 -0
  54. package/dist/templates/nextjs/src/lib/next-config/plugins/graphql.js +32 -0
  55. package/dist/templates/nextjs/src/lib/next-config/plugins/monorepo.js +27 -0
  56. package/dist/templates/nextjs/src/lib/page-props-factory/index.ts +50 -0
  57. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/componentProps.ts +38 -0
  58. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/normalMode.ts +75 -0
  59. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/previewMode.ts +27 -0
  60. package/dist/templates/nextjs/src/lib/page-props.ts +16 -0
  61. package/dist/templates/nextjs/src/lib/sitemap-fetcher/index.ts +25 -0
  62. package/dist/templates/nextjs/src/lib/sitemap-fetcher/plugins/graphqlSitemapService.ts +36 -0
  63. package/dist/templates/nextjs/src/pages/404.tsx +5 -0
  64. package/dist/templates/nextjs/src/pages/[[...path]].tsx +91 -0
  65. package/dist/templates/nextjs/src/pages/_app.tsx +19 -0
  66. package/dist/templates/nextjs/src/pages/_error.tsx +35 -0
  67. package/dist/templates/nextjs/src/pages/api/editing/data/[key].ts +24 -0
  68. package/dist/templates/nextjs/src/pages/api/editing/render.ts +30 -0
  69. package/dist/templates/nextjs/src/temp/.gitignore +3 -0
  70. package/dist/templates/nextjs/src/temp/GraphQLIntrospectionResult.json +22216 -0
  71. package/dist/templates/nextjs/tsconfig.json +42 -0
  72. package/dist/templates/nextjs/tsconfig.scripts.json +6 -0
  73. package/dist/templates/nextjs-styleguide/data/component-content/.gitignore +0 -0
  74. package/dist/templates/nextjs-styleguide/data/component-content/Styleguide/ContentReuse/LoremIpsumContentBlock/en.yml +9 -0
  75. package/dist/templates/nextjs-styleguide/data/content/.gitignore +0 -0
  76. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ContentListField/Item1/en.yml +6 -0
  77. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ContentListField/Item2/en.yml +6 -0
  78. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ItemLinkField/Item1/en.yml +6 -0
  79. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ItemLinkField/Item2/en.yml +6 -0
  80. package/dist/templates/nextjs-styleguide/data/dictionary/en.yml +4 -0
  81. package/dist/templates/nextjs-styleguide/data/dictionary/{{language}}.yml +4 -0
  82. package/dist/templates/nextjs-styleguide/data/media/files/jss.pdf +0 -0
  83. package/dist/templates/nextjs-styleguide/data/media/img/jss_logo.png +0 -0
  84. package/dist/templates/nextjs-styleguide/data/media/img/sc_logo.png +0 -0
  85. package/dist/templates/nextjs-styleguide/data/routes/en.yml +63 -0
  86. package/dist/templates/nextjs-styleguide/data/routes/graphql/en.yml +27 -0
  87. package/dist/templates/nextjs-styleguide/data/routes/graphql/sample-1/en.yml +9 -0
  88. package/dist/templates/nextjs-styleguide/data/routes/graphql/sample-2/en.yml +9 -0
  89. package/dist/templates/nextjs-styleguide/data/routes/styleguide/custom-route-type/en.yml +12 -0
  90. package/dist/templates/nextjs-styleguide/data/routes/styleguide/en.yml +246 -0
  91. package/dist/templates/nextjs-styleguide/data/routes/styleguide/{{language}}.yml +25 -0
  92. package/dist/templates/nextjs-styleguide/data/routes/{{language}}.yml +4 -0
  93. package/dist/templates/nextjs-styleguide/package.json +13 -0
  94. package/dist/templates/nextjs-styleguide/scripts/disconnected-mode-proxy.ts +48 -0
  95. package/dist/templates/nextjs-styleguide/scripts/scaffold-component.ts +130 -0
  96. package/dist/templates/nextjs-styleguide/scripts/templates/component-manifest.ts +30 -0
  97. package/dist/templates/nextjs-styleguide/sitecore/definitions/component-content.sitecore.ts +117 -0
  98. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/ContentBlock.sitecore.ts +19 -0
  99. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Checkbox.sitecore.ts +23 -0
  100. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-ContentList.sitecore.ts +32 -0
  101. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Custom.sitecore.ts +23 -0
  102. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Date.sitecore.ts +23 -0
  103. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-File.sitecore.ts +20 -0
  104. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Image.sitecore.ts +23 -0
  105. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-ItemLink.sitecore.ts +32 -0
  106. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Link.sitecore.ts +25 -0
  107. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Number.sitecore.ts +20 -0
  108. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-RichText.sitecore.ts +28 -0
  109. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Text.sitecore.ts +28 -0
  110. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-ConnectedDemo.sitecore.ts +18 -0
  111. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-IntegratedDemo.sitecore.graphql +71 -0
  112. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-IntegratedDemo.sitecore.ts +25 -0
  113. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-Layout.sitecore.ts +15 -0
  114. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-ComponentParams.sitecore.ts +20 -0
  115. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-CustomRouteType.sitecore.ts +31 -0
  116. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Reuse.sitecore.ts +20 -0
  117. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Tabs-Tab.sitecore.ts +23 -0
  118. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Tabs.sitecore.ts +20 -0
  119. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout.sitecore.ts +15 -0
  120. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Multilingual.sitecore.ts +26 -0
  121. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-RouteFields.sitecore.ts +22 -0
  122. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Section.sitecore.ts +16 -0
  123. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-SitecoreContext.sitecore.ts +19 -0
  124. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Tracking.sitecore.ts +19 -0
  125. package/dist/templates/nextjs-styleguide/sitecore/definitions/config.js +5 -0
  126. package/dist/templates/nextjs-styleguide/sitecore/definitions/content.sitecore.ts +117 -0
  127. package/dist/templates/nextjs-styleguide/sitecore/definitions/dictionary.sitecore.ts +52 -0
  128. package/dist/templates/nextjs-styleguide/sitecore/definitions/placeholders.sitecore.ts +21 -0
  129. package/dist/templates/nextjs-styleguide/sitecore/definitions/routes.sitecore.ts +88 -0
  130. package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-ContentList-Template.sitecore.ts +12 -0
  131. package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-Explanatory-Component.sitecore.ts +20 -0
  132. package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-ItemLink-Template.sitecore.ts +13 -0
  133. package/dist/templates/nextjs-styleguide/src/Navigation.tsx +41 -0
  134. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Checkbox.tsx +52 -0
  135. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-ContentList.tsx +58 -0
  136. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Custom.tsx +25 -0
  137. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Date.tsx +55 -0
  138. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-File.tsx +30 -0
  139. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Image.tsx +58 -0
  140. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-ItemLink.tsx +50 -0
  141. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Link.tsx +46 -0
  142. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Number.tsx +34 -0
  143. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-RichText.tsx +35 -0
  144. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Text.tsx +43 -0
  145. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-ConnectedDemo.dynamic.graphql +69 -0
  146. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-ConnectedDemo.dynamic.tsx +148 -0
  147. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-IntegratedDemo.tsx +130 -0
  148. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-Layout.tsx +37 -0
  149. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-ComponentParams.tsx +47 -0
  150. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-CustomRouteType.tsx +37 -0
  151. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Reuse.tsx +45 -0
  152. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Tabs-Tab.tsx +41 -0
  153. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Tabs.tsx +111 -0
  154. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout.tsx +68 -0
  155. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Multilingual.tsx +50 -0
  156. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-RouteFields.tsx +37 -0
  157. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Section.tsx +22 -0
  158. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-SitecoreContext.tsx +25 -0
  159. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Specimen.tsx +41 -0
  160. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Tracking.tsx +341 -0
  161. package/dist/templates/nextjs-styleguide/src/lib/component-props/styleguide.ts +11 -0
  162. package/dist/templates/nextjs-styleguide/src/lib/next-config/plugins/disconnected.js +43 -0
  163. package/dist/templates/nextjs-styleguide/src/lib/next-config/plugins/styleguide.js +10 -0
  164. package/dist/templates/nextjs-styleguide/src/lib/sitemap-fetcher/plugins/disconnectedSitemapService.ts +46 -0
  165. package/dist/templates/nextjs-styleguide/src/pages/_app.tsx +33 -0
  166. package/package.json +61 -0
@@ -0,0 +1,20 @@
1
+ // eslint-disable-next-line no-unused-vars
2
+ import { CommonFieldTypes, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
3
+
4
+ /**
5
+ * This is a standalone _base template_ that is inherited by components in the styleguide that need to
6
+ * show explanatory text. The fields on this template are implicitly available on inherited components.
7
+ * Note: inherited fields cannot be modified when inherited (e.g. with different validation rules or help text).
8
+ * Ensure that there is truly an inheritance relationship and not merely "they happen share some fields" before using inheritance.
9
+ * @param {Manifest} manifest Manifest instance to add components to
10
+ */
11
+ export default function StyleguideExplanatoryComponent(manifest: Manifest): void {
12
+ manifest.addTemplate({
13
+ name: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-Explanatory-Component',
14
+ id: '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
15
+ fields: [
16
+ { name: 'heading', type: CommonFieldTypes.SingleLineText },
17
+ { name: 'description', type: CommonFieldTypes.RichText },
18
+ ],
19
+ });
20
+ }
@@ -0,0 +1,13 @@
1
+ // eslint-disable-next-line no-unused-vars
2
+ import { CommonFieldTypes, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
3
+
4
+ /**
5
+ * This is the data template for an individual _item_ in the Styleguide's Content List field demo.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideItemLinkItemTemplate(manifest: Manifest): void {
9
+ manifest.addTemplate({
10
+ name: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-ItemLink-Item-Template',
11
+ fields: [{ name: 'textField', type: CommonFieldTypes.SingleLineText }],
12
+ });
13
+ }
@@ -0,0 +1,41 @@
1
+ import Link from 'next/link';
2
+ import { useI18n } from 'next-localization';
3
+ import { getPublicUrl } from '@sitecore-jss/sitecore-jss-nextjs';
4
+
5
+ // Prefix public assets with a public URL to enable compatibility with Sitecore Experience Editor.
6
+ // If you're not supporting the Experience Editor, you can remove this.
7
+ const publicUrl = getPublicUrl();
8
+
9
+ const Navigation = (): JSX.Element => {
10
+ const { t } = useI18n();
11
+
12
+ return (
13
+ <div className="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom">
14
+ <h5 className="my-0 mr-md-auto font-weight-normal">
15
+ <Link href="/">
16
+ <a className="text-dark">
17
+ <img src={`${publicUrl}/sc_logo.svg`} alt="Sitecore" />
18
+ </a>
19
+ </Link>
20
+ </h5>
21
+ <nav className="my-2 my-md-0 mr-md-3">
22
+ <a
23
+ className="p-2 text-dark"
24
+ href="https://jss.sitecore.com"
25
+ target="_blank"
26
+ rel="noopener noreferrer"
27
+ >
28
+ {t('Documentation')}
29
+ </a>
30
+ <Link href="/styleguide">
31
+ <a className="p-2 text-dark">{t('Styleguide')}</a>
32
+ </Link>
33
+ <Link href="/graphql">
34
+ <a className="p-2 text-dark">{t('GraphQL')}</a>
35
+ </Link>
36
+ </nav>
37
+ </div>
38
+ );
39
+ };
40
+
41
+ export default Navigation;
@@ -0,0 +1,52 @@
1
+ import { Field, getFieldValue } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageCheckboxProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ checkbox: Field<boolean>;
10
+ checkbox2: Field<boolean>;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * Demonstrates usage of a Checkbox (boolean) content field within JSS.
16
+ */
17
+ const StyleguideFieldUsageCheckbox = (props: StyleguideFieldUsageCheckboxProps): JSX.Element => (
18
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-checkbox">
19
+ {/* Checkbox fields do not have the ability to be inline edited, so they are directly accessed via their value: */}
20
+ <ul>
21
+ {/*
22
+ The getFieldValue helper allows safely extracting a field value that could be undefined,
23
+ without needing to check that props.fields or props.fields.checkbox are traversable,
24
+ and allowing the specification of an optional default value (default is undefined if unspecified).
25
+ */}
26
+ {props.fields && props.fields.checkbox && props.fields.checkbox.value && (
27
+ <li>
28
+ <code>checkbox</code> is true
29
+ </li>
30
+ )}
31
+ {!props.fields ||
32
+ !props.fields.checkbox ||
33
+ (!props.fields.checkbox.value && (
34
+ <li>
35
+ <code>checkbox</code> is false
36
+ </li>
37
+ ))}
38
+ {getFieldValue(props.fields, 'checkbox2', false) && (
39
+ <li>
40
+ <code>checkbox2</code> is true
41
+ </li>
42
+ )}
43
+ {!getFieldValue(props.fields, 'checkbox2', false) && (
44
+ <li>
45
+ <code>checkbox2</code> is false
46
+ </li>
47
+ )}
48
+ </ul>
49
+ </StyleguideSpecimen>
50
+ );
51
+
52
+ export default StyleguideFieldUsageCheckbox;
@@ -0,0 +1,58 @@
1
+ import { Field, Text, Item, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageContentListProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ sharedContentList: Item[];
10
+ localContentList: Item[];
11
+ };
12
+ };
13
+
14
+ /**
15
+ * Demonstrates usage of a Content List field type within JSS.
16
+ * Content Lists are references to 0..n other content items.
17
+ * In Sitecore terms, this maps by default to a Treelist field.
18
+ */
19
+ const StyleguideFieldUsageContentList = (
20
+ props: StyleguideFieldUsageContentListProps
21
+ ): JSX.Element => {
22
+ const { sharedContentList, localContentList } = props.fields;
23
+
24
+ return (
25
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-content-list">
26
+ <h5>Shared Content List</h5>
27
+ {/*
28
+ Content list fields are returned with their value as an array of the referenced items.
29
+ So we can use the .map() array function to traverse them. Ensure a `key` attribute is set
30
+ on each element to make React's DOM updating happy:
31
+ */}
32
+ {sharedContentList &&
33
+ sharedContentList.map((listItem, index) => (
34
+ <div key={`sharedListItem-${index}`}>
35
+ {/* The referenced item's fields can be rendered and edited using normal helper components: */}
36
+ <p>
37
+ Field: <Text field={listItem.fields.textField as Field<string>} />
38
+ </p>
39
+ </div>
40
+ ))}
41
+
42
+ <h5>Local Content List</h5>
43
+ {localContentList &&
44
+ localContentList.map((listItem, index) => (
45
+ <div key={`localListItem-${index}`}>
46
+ {/* The referenced item's fields can be rendered and edited using normal helper components: */}
47
+ <p>
48
+ Field: <Text field={listItem.fields.textField as Field<string>} />
49
+ </p>
50
+ </div>
51
+ ))}
52
+ </StyleguideSpecimen>
53
+ );
54
+ };
55
+
56
+ export default withDatasourceCheck()<StyleguideFieldUsageContentListProps>(
57
+ StyleguideFieldUsageContentList
58
+ );
@@ -0,0 +1,25 @@
1
+ import { Field, Text, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageCustomProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ customIntField: Field<string>;
10
+ };
11
+ };
12
+
13
+ /**
14
+ * Demonstrates usage of a custom content field type within JSS.
15
+ * See /sitecore/definitions/components/Styleguide-FieldUsage-Custom.sitecore.js
16
+ * for the definition of the structure of the custom field. This code is just for display.
17
+ */
18
+ const StyleguideFieldUsageCustom = (props: StyleguideFieldUsageCustomProps): JSX.Element => (
19
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-custom">
20
+ {/* Because the integer field is essentially text, we can render it with the Text helper */}
21
+ <Text field={props.fields.customIntField} />
22
+ </StyleguideSpecimen>
23
+ );
24
+
25
+ export default withDatasourceCheck()<StyleguideFieldUsageCustomProps>(StyleguideFieldUsageCustom);
@@ -0,0 +1,55 @@
1
+ import { DateField, Field, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageDateProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ date: Field<string>;
10
+ dateTime: Field<string>;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * Demonstrates usage of date and time content field types within JSS.
16
+ */
17
+ const StyleguideFieldUsageDate = (props: StyleguideFieldUsageDateProps): JSX.Element => {
18
+ return (
19
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-date">
20
+ <ul>
21
+ <li>
22
+ Date helper: <DateField field={props.fields.date} />
23
+ </li>
24
+ <li>
25
+ Date helper (datetime): <DateField field={props.fields.dateTime} />
26
+ </li>
27
+ <li>
28
+ UTC Date string:&nbsp;
29
+ {/*
30
+ Date helper supports a render props API to give you direct access to the JS Date object for formatting.
31
+ IMPORTANT: the render prop is ignored when in Experience Editor mode to support inline editing.
32
+ */}
33
+ <DateField field={props.fields.date} render={(date) => date && date.toUTCString()} />
34
+ </li>
35
+ <li>
36
+ Localized Date string (local timezone):&nbsp;
37
+ <DateField
38
+ field={props.fields.date}
39
+ render={(date) => date && date.toLocaleDateString()}
40
+ />
41
+ </li>
42
+ <li>
43
+ Localized DateTime string (local timezone):&nbsp;
44
+ {/* React components can also be returned from the render props for wrapping */}
45
+ <DateField
46
+ field={props.fields.dateTime}
47
+ render={(date) => <em>{date && date.toLocaleString()}</em>}
48
+ />
49
+ </li>
50
+ </ul>
51
+ </StyleguideSpecimen>
52
+ );
53
+ };
54
+
55
+ export default withDatasourceCheck()<StyleguideFieldUsageDateProps>(StyleguideFieldUsageDate);
@@ -0,0 +1,30 @@
1
+ import { File, FileField, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageFileProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ file: FileField;
10
+ };
11
+ };
12
+
13
+ /**
14
+ * Demonstrates usage of a File content field within JSS.
15
+ * File types are stored within Sitecore's Media Library data, and can be edited.
16
+ */
17
+ const StyleguideFieldUsageFile = (props: StyleguideFieldUsageFileProps): JSX.Element => (
18
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-file">
19
+ {/* Renders a file link */}
20
+ <File field={props.fields.file} />
21
+ <br />
22
+
23
+ {/* Renders a file link with a custom body and opening in a new tab */}
24
+ <File field={props.fields.file} target="_blank">
25
+ Custom link body
26
+ </File>
27
+ </StyleguideSpecimen>
28
+ );
29
+
30
+ export default withDatasourceCheck()<StyleguideFieldUsageFileProps>(StyleguideFieldUsageFile);
@@ -0,0 +1,58 @@
1
+ import { Image, ImageField, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageImageProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ sample1: ImageField;
10
+ sample2: ImageField;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * Demonstrates usage of an Image content field within JSS.
16
+ * Image field data is uploaded into the Sitecore Media Library.
17
+ */
18
+ const StyleguideFieldUsageImage = (props: StyleguideFieldUsageImageProps): JSX.Element => (
19
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-image">
20
+ <p>Plain image</p>
21
+ <Image media={props.fields.sample1} />
22
+
23
+ {/*
24
+ Advanced image usage example
25
+ editable: controls whether image can be edited in Sitecore Experience Editor
26
+ imageParams: parameters that are passed to Sitecore to perform server-side resizing of the image.
27
+ Sample rescales image to max 100x50 dimensions on the server, respecting aspect ratio
28
+ IMPORTANT: imageParams must be whitelisted for resizing to occur. See /sitecore/config/*.config (search for 'allowedMediaParams')
29
+ any other attributes: pass through to img tag
30
+ */}
31
+ <p>Advanced image (not editable)</p>
32
+ <Image
33
+ field={props.fields.sample2}
34
+ editable={false}
35
+ imageParams={{ mw: 100, mh: 50 }}
36
+ height="50"
37
+ width="94"
38
+ data-sample="other-attributes-pass-through"
39
+ />
40
+
41
+ {/*
42
+ Srcset adaptive image usage example
43
+ Adaptive srcsets are supported using Sitecore server-side resizing.
44
+ The `srcSet` can use Sitecore image resizing parameters (i.e. w, h, mw, mh).
45
+ Sample create a srcset using two sizes (server resizing), 300 and 100px max widths, respecting aspect ratio.
46
+ IMPORTANT: srcSet params must be whitelisted for adaptive resizing to occur. See /sitecore/config/*.config (search for 'allowedMediaParams')
47
+ */}
48
+ <p>Srcset responsive image</p>
49
+ <Image
50
+ field={props.fields.sample2}
51
+ srcSet={[{ mw: 300 }, { mw: 100 }]}
52
+ sizes="(min-width: 960px) 300px, 100px"
53
+ className="img-fluid"
54
+ />
55
+ </StyleguideSpecimen>
56
+ );
57
+
58
+ export default withDatasourceCheck()<StyleguideFieldUsageImageProps>(StyleguideFieldUsageImage);
@@ -0,0 +1,50 @@
1
+ import { Field, Text, Item, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageItemLinkProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ sharedItemLink: Item;
10
+ localItemLink: Item;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * Demonstrates usage of a Content Link content field within JSS.
16
+ * Content links are a reference to a single other piece of content.
17
+ */
18
+ const StyleguideFieldUsageItemLink = (props: StyleguideFieldUsageItemLinkProps): JSX.Element => {
19
+ const { sharedItemLink, localItemLink } = props.fields;
20
+
21
+ return (
22
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-itemlink">
23
+ <h5>Shared Item Link</h5>
24
+ {/*
25
+ Item link fields are returned with their value as the referenced item value.
26
+ */}
27
+ {sharedItemLink && (
28
+ <div>
29
+ {/* The referenced item's fields can be rendered and edited using normal helper components: */}
30
+ <p>
31
+ Field: <Text field={sharedItemLink.fields.textField as Field<string>} />
32
+ </p>
33
+ </div>
34
+ )}
35
+
36
+ <h5>Local Item Link</h5>
37
+ {localItemLink && (
38
+ <div>
39
+ <p>
40
+ Field: <Text field={localItemLink.fields.textField as Field<string>} />
41
+ </p>
42
+ </div>
43
+ )}
44
+ </StyleguideSpecimen>
45
+ );
46
+ };
47
+
48
+ export default withDatasourceCheck()<StyleguideFieldUsageItemLinkProps>(
49
+ StyleguideFieldUsageItemLink
50
+ );
@@ -0,0 +1,46 @@
1
+ import { Link, LinkField, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageLinkProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ externalLink: LinkField;
10
+ internalLink: LinkField;
11
+ emailLink: LinkField;
12
+ paramsLink: LinkField;
13
+ };
14
+ };
15
+
16
+ /**
17
+ * Demonstrates usage of a General Link (hyperlink) content field within JSS.
18
+ */
19
+ const StyleguideFieldUsageLink = (props: StyleguideFieldUsageLinkProps): JSX.Element => (
20
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-link">
21
+ External link:&nbsp;
22
+ <Link field={props.fields.externalLink} />
23
+ <br />
24
+ Internal link:&nbsp;
25
+ <Link field={props.fields.internalLink}>
26
+ <em>HTML</em> or other components can be used within link renderers, for example links to
27
+ images.
28
+ </Link>
29
+ <br />
30
+ Email link:&nbsp;
31
+ <Link field={props.fields.emailLink} />
32
+ <br />
33
+ All possible content params link:&nbsp;
34
+ <Link field={props.fields.paramsLink} />
35
+ <br />
36
+ The link component accepts params of its own:&nbsp;
37
+ <Link
38
+ field={props.fields.externalLink}
39
+ showLinkTextWithChildrenPresent={true}
40
+ className="font-weight-bold"
41
+ data-otherattributes="pass-through-to-anchor-tag"
42
+ />
43
+ </StyleguideSpecimen>
44
+ );
45
+
46
+ export default withDatasourceCheck()<StyleguideFieldUsageLinkProps>(StyleguideFieldUsageLink);
@@ -0,0 +1,34 @@
1
+ import { Text, Field, getFieldValue, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageTextProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ sample: Field<string>;
10
+ };
11
+ };
12
+
13
+ /**
14
+ * Demonstrates usage of a Number (decimal) content field within JSS.
15
+ */
16
+ const StyleguideFieldUsageText = (props: StyleguideFieldUsageTextProps): JSX.Element => {
17
+ const fieldValue = getFieldValue(props.fields, 'sample');
18
+
19
+ return (
20
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-number">
21
+ {/* Basic emission of a number field for editing can be done with the <Text> component. */}
22
+ <Text field={props.fields.sample} />
23
+
24
+ {/* Direct access to the value, which is a JS number, is also supported. */}
25
+ <p>
26
+ JS value type: {typeof fieldValue}
27
+ <br />
28
+ JS value: {fieldValue}
29
+ </p>
30
+ </StyleguideSpecimen>
31
+ );
32
+ };
33
+
34
+ export default withDatasourceCheck()<StyleguideFieldUsageTextProps>(StyleguideFieldUsageText);
@@ -0,0 +1,35 @@
1
+ import { RichText, Field, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageRichTextProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ sample: Field<string>;
10
+ sample2: Field<string>;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * Demonstrates usage of a Rich Text (HTML) content field within JSS.
16
+ */
17
+ const StyleguideFieldUsageRichText = (props: StyleguideFieldUsageRichTextProps): JSX.Element => (
18
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-richtext">
19
+ {/* Basic use of a rich text field. Wraps in a <div>. */}
20
+ <RichText field={props.fields.sample} />
21
+
22
+ {/* Advanced usage of rich text field. Specifies a custom wrapper tag, turns off Sitecore editing, and has a CSS class on the wrapper */}
23
+ <RichText
24
+ field={props.fields.sample2}
25
+ tag="section"
26
+ editable={false}
27
+ className="text-center"
28
+ data-sample="other-attributes-pass-through"
29
+ />
30
+ </StyleguideSpecimen>
31
+ );
32
+
33
+ export default withDatasourceCheck()<StyleguideFieldUsageRichTextProps>(
34
+ StyleguideFieldUsageRichText
35
+ );
@@ -0,0 +1,43 @@
1
+ import { Text, Field, getFieldValue, withDatasourceCheck } from '@sitecore-jss/sitecore-jss-nextjs';
2
+ import StyleguideSpecimen from 'components/styleguide/Styleguide-Specimen';
3
+ import { ComponentProps } from 'lib/component-props';
4
+ import { StyleguideSpecimenFields } from 'lib/component-props/styleguide';
5
+
6
+ type StyleguideFieldUsageTextProps = ComponentProps &
7
+ StyleguideSpecimenFields & {
8
+ fields: {
9
+ sample: Field<string>;
10
+ sample2: Field<string>;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * Demonstrates usage of a Text content field within JSS.
16
+ * Text fields are HTML encoded by default.
17
+ */
18
+ const StyleguideFieldUsageText = (props: StyleguideFieldUsageTextProps): JSX.Element => (
19
+ <StyleguideSpecimen {...props} e2eId="styleguide-fieldusage-text">
20
+ {/* Basic use of a text field. No wrapper. */}
21
+ <Text field={props.fields.sample} />
22
+
23
+ {/* Advanced usage of text field. Specifies a wrapper tag, turns off Sitecore editing, supports raw HTML, and has a CSS class on the wrapper */}
24
+ <Text
25
+ field={props.fields.sample2}
26
+ tag="section"
27
+ editable={false}
28
+ encode={false}
29
+ className="font-weight-bold"
30
+ data-sample="other-attributes-pass-through"
31
+ />
32
+
33
+ {/*
34
+ Use this API when you need direct programmatic access to a field as a variable.
35
+ Note: editing such a value in Experience Editor is not possible, and direct field
36
+ editing must be used to edit a value emitted like this (the pencil icon when the rendering
37
+ is selected in xEditor)
38
+ */}
39
+ <div>Raw value (not editable): {getFieldValue(props.fields, 'sample')}</div>
40
+ </StyleguideSpecimen>
41
+ );
42
+
43
+ export default withDatasourceCheck()<StyleguideFieldUsageTextProps>(StyleguideFieldUsageText);
@@ -0,0 +1,69 @@
1
+ # This file contains a GraphQL query that will be executed and the result provided to
2
+ # your JSS component. You can run this query in GraphiQL ($endpoint/ui) for a nice editing experience.
3
+
4
+ # Note that we're executing _two queries_ (datasource and contextItem)
5
+ # within the context of the ConnectedDemoQuery _operation_. This makes it
6
+ # very efficient at gathering data from multiple sources.
7
+
8
+ query ConnectedDemoQuery($datasource: String!, $contextItem: String!, $language: String!) {
9
+ # Datasource query
10
+ # $datasource should be set to the ID of the rendering's datasource item
11
+ datasource: item(path: $datasource, language: $language) {
12
+ id
13
+ name
14
+ # Strongly-typed querying on known templates is possible!
15
+ ...on <%- appPrefix ? `${helper.getPascalCaseName(appName)}` : "" %>GraphQLConnectedDemo {
16
+ # Single-line text field
17
+ sample1 {
18
+ # the 'jsonValue' field is a JSON blob that represents the object that
19
+ # should be passed to JSS field rendering helpers (i.e. text, image, link)
20
+ jsonValue
21
+ value
22
+ }
23
+ # General Link field
24
+ sample2 {
25
+ jsonValue
26
+ # Structured querying of the field's values is possible
27
+ text
28
+ target
29
+ url
30
+ # Access to the template definition is possible
31
+ definition {
32
+ type
33
+ shared
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ # Context/route item query
40
+ # $contextItem should be set to the ID of the current context item (the route item)
41
+ contextItem: item(path: $contextItem, language: $language) {
42
+ id
43
+ # Get the page title from the app route template
44
+ ...on <%- appPrefix ? `${helper.getPascalCaseName(appName)}` : "" %>AppRoute {
45
+ pageTitle {
46
+ value
47
+ }
48
+ }
49
+
50
+ # List the children of the current route
51
+ children(hasLayout: true) {
52
+ results {
53
+ id
54
+ # typing fragments can be used anywhere!
55
+ # so in this case, we're grabbing the 'pageTitle'
56
+ # field on all child route items.
57
+ ...on <%- appPrefix ? `${helper.getPascalCaseName(appName)}` : "" %>AppRoute {
58
+ pageTitle {
59
+ jsonValue
60
+ value
61
+ }
62
+ }
63
+ url{
64
+ path
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }