@hubspot/cms-component-library 0.3.1 → 0.3.3

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 (25) hide show
  1. package/components/componentLibrary/Accordion/AccordionItem/index.module.scss +4 -0
  2. package/components/componentLibrary/Accordion/AccordionTitle/ContentFields.tsx +1 -0
  3. package/components/componentLibrary/Accordion/AccordionTitle/icons.tsx +19 -0
  4. package/components/componentLibrary/Accordion/AccordionTitle/index.module.scss +4 -0
  5. package/components/componentLibrary/Accordion/AccordionTitle/index.tsx +3 -1
  6. package/components/componentLibrary/Accordion/AccordionTitle/types.ts +1 -1
  7. package/components/componentLibrary/Accordion/llm.txt +7 -6
  8. package/components/componentLibrary/Accordion/stories/Accordion.stories.tsx +21 -0
  9. package/components/componentLibrary/Divider/StyleFields.tsx +72 -14
  10. package/components/componentLibrary/Divider/index.tsx +31 -16
  11. package/components/componentLibrary/Divider/llm.txt +97 -103
  12. package/components/componentLibrary/Divider/stories/Divider.stories.tsx +30 -19
  13. package/components/componentLibrary/Divider/types.ts +31 -20
  14. package/components/componentLibrary/Icon/StyleFields.tsx +69 -0
  15. package/components/componentLibrary/Icon/index.module.scss +11 -0
  16. package/components/componentLibrary/Icon/index.tsx +31 -4
  17. package/components/componentLibrary/Icon/llm.txt +50 -10
  18. package/components/componentLibrary/Icon/types.ts +29 -0
  19. package/components/componentLibrary/Text/ContentFields.tsx +66 -0
  20. package/components/componentLibrary/Text/index.module.scss +3 -0
  21. package/components/componentLibrary/Text/index.tsx +27 -0
  22. package/components/componentLibrary/Text/llm.txt +170 -0
  23. package/components/componentLibrary/Text/types.ts +16 -0
  24. package/package.json +4 -4
  25. package/components/componentLibrary/Divider/ContentFields.tsx +0 -63
@@ -0,0 +1,170 @@
1
+ # Text Component
2
+
3
+ A component for rendering HubSpot CMS rich text field content.
4
+
5
+ ## Import path
6
+ ```tsx
7
+ import Text from '@hubspot/cms-component-library/Text';
8
+ ```
9
+
10
+ ## Purpose
11
+
12
+ The Text component wraps HubSpot's native `RichText` component to provide a consistent interface for rendering editable rich text content in HubSpot CMS modules. It handles the connection between a CMS field and the rendered output, while exposing a single CSS variable for text color theming. Use this component whenever a module needs a rich text area managed through the HubSpot page editor.
13
+
14
+ ## Component Structure
15
+
16
+ ```
17
+ Text/
18
+ ├── index.tsx # Main component wrapping HubSpot RichText
19
+ ├── types.ts # TypeScript type definitions
20
+ ├── ContentFields.tsx # HubSpot field definitions for rich text content
21
+ └── index.module.scss # CSS module with design tokens
22
+ ```
23
+
24
+ ## Components
25
+
26
+ ### Text (Main Component)
27
+
28
+ **Purpose:** Renders a HubSpot CMS rich text field at the given `fieldPath`, applying CSS module class and CSS variable theming for text color.
29
+
30
+ **Props:**
31
+ ```tsx
32
+ {
33
+ fieldPath?: string; // Path to the RichText field in HubSpot CMS (e.g., 'text', 'bodyContent')
34
+ className?: string; // Additional CSS classes (default: '')
35
+ style?: CSSVariables; // Inline styles, supports CSS custom properties (default: {})
36
+ }
37
+ ```
38
+
39
+ ## Usage Examples
40
+
41
+ ### Basic Text
42
+
43
+ ```tsx
44
+ import Text from '@hubspot/cms-component-library/Text';
45
+
46
+ <Text fieldPath="text" />
47
+ ```
48
+
49
+ ## HubSpot CMS Integration
50
+
51
+ ### Field Definitions
52
+
53
+ The Text component provides `ContentFields` for defining a `RichTextField` inside a HubSpot CMS module.
54
+
55
+ #### ContentFields
56
+
57
+ Configurable props for customizing the text field label, name, default value, and editor features:
58
+
59
+ ```tsx
60
+ <Text.ContentFields
61
+ textLabel="Body text"
62
+ textName="bodyText"
63
+ textDefault="<p>Enter your content here.</p>"
64
+ textFeatureSet="bodyContent"
65
+ />
66
+ ```
67
+
68
+ **Props:**
69
+ - `textLabel` (default: `'Text'`): Label shown in the HubSpot editor
70
+ - `textName` (default: `'text'`): Field name used as the `fieldPath` reference in the component
71
+ - `textDefault` (default: `'<p>Text goes here.</p>'`): Default HTML content for the field
72
+ - `textFeatureSet` (`'bodyContent' | 'heading'`, default: `'bodyContent'`): Controls the editor toolbar
73
+ - Use `'bodyContent'` for full-featured editing (includes image, emoji, table, embed, video, and more)
74
+ - Use `'heading'` for a reduced feature set suited to titles and captions (no rich media)
75
+
76
+ **Fields:**
77
+ - `text` (name set by `textName`): RichTextField for the rich text content
78
+
79
+ #### Style Fields
80
+
81
+ **Note:** There are no style fields included with this component. Do not try to import them.
82
+
83
+ ### Module Usage Example
84
+
85
+ ```tsx
86
+ import Text from '@hubspot/cms-component-library/Text';
87
+
88
+ export default function ArticleModule() {
89
+ return (
90
+ <Text fieldPath="bodyText" />
91
+ );
92
+ }
93
+ ```
94
+
95
+ ### Module Fields Example
96
+
97
+ ```tsx
98
+ import { ModuleFields } from '@hubspot/cms-components/fields';
99
+ import Text from '@hubspot/cms-component-library/Text';
100
+
101
+ export const fields = (
102
+ <ModuleFields>
103
+ <Text.ContentFields
104
+ textLabel="Body text"
105
+ textName="bodyText"
106
+ textDefault="<p>Enter your content here.</p>"
107
+ textFeatureSet="bodyContent"
108
+ />
109
+ </ModuleFields>
110
+ );
111
+ ```
112
+
113
+ ### Multiple Text Fields in One Module
114
+
115
+ ```tsx
116
+ import { ModuleFields } from '@hubspot/cms-components/fields';
117
+ import Text from '@hubspot/cms-component-library/Text';
118
+
119
+ export const fields = (
120
+ <ModuleFields>
121
+ <Text.ContentFields
122
+ textLabel="Heading text"
123
+ textName="headingText"
124
+ textDefault="<p>Enter your heading.</p>"
125
+ textFeatureSet="heading"
126
+ />
127
+ <Text.ContentFields
128
+ textLabel="Body text"
129
+ textName="bodyText"
130
+ textDefault="<p>Enter your body content.</p>"
131
+ textFeatureSet="bodyContent"
132
+ />
133
+ </ModuleFields>
134
+ );
135
+
136
+ export default function ArticleModule() {
137
+ return (
138
+ <div>
139
+ <Text fieldPath="headingText" />
140
+ <Text fieldPath="bodyText" />
141
+ </div>
142
+ );
143
+ }
144
+ ```
145
+
146
+ ## Styling
147
+
148
+ ### CSS Variables
149
+
150
+ **Base Styles:**
151
+ - `--hscl-text-color`: Text color applied to the rendered rich text content (default: `currentColor`)
152
+
153
+ ## Accessibility
154
+
155
+ - **Semantic HTML**: Content is rendered directly from the HubSpot CMS editor output, which produces standard HTML elements (`<p>`, `<h1>`–`<h6>`, `<ul>`, `<ol>`, etc.)
156
+ - **Structured content**: Encourage editors to use proper heading hierarchy and list elements within the rich text editor for screen reader compatibility
157
+ - **Link accessibility**: Links created in the rich text editor will render as native `<a>` elements
158
+
159
+ ## Best Practices
160
+
161
+ - **Match `fieldPath` to `textName`**: The `fieldPath` prop on the component must match the `textName` prop on `ContentFields` — they reference the same CMS field
162
+ - **Choose the right feature set**: Use `'heading'` for simpler text areas (titles, captions) to keep the editor toolbar uncluttered; use `'bodyContent'` for full article or section content
163
+ - **Style fields**: There are no style fields for this component. Do not try to import them
164
+ - **CSS Variables for theming**: Override `--hscl-text-color` via the `style` prop rather than using CSS selectors that target the component's internals
165
+ - **Multiple fields per module**: You can render multiple `Text` components in one module by giving each a unique `textName` / `fieldPath` pair
166
+
167
+ ## Related Components
168
+
169
+ - **Button**: Use for call-to-action elements within or adjacent to text content
170
+ - **Link**: Use for standalone clickable text or wrapped content that requires a link without rich text editing
@@ -0,0 +1,16 @@
1
+ import type { CSSVariables } from '../utils/types.js';
2
+
3
+ export type TextProps = {
4
+ fieldPath?: string;
5
+ className?: string;
6
+ style?: CSSVariables;
7
+ };
8
+
9
+ export type TextFeatureSet = 'bodyContent' | 'heading';
10
+
11
+ export type ContentFieldsProps = {
12
+ textLabel?: string;
13
+ textName?: string;
14
+ textDefault?: string;
15
+ textFeatureSet?: TextFeatureSet;
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-component-library",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "HubSpot CMS React component library for building CMS modules",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
@@ -21,9 +21,8 @@
21
21
  },
22
22
  "type": "module",
23
23
  "dependencies": {
24
- "@hubspot/cms-components": "^1.2.13",
25
- "sass-embedded": "^1.90.0",
26
- "tsx": "^4.20.5"
24
+ "@hubspot/cms-components": "1.2.17",
25
+ "sass-embedded": "^1.97.3"
27
26
  },
28
27
  "peerDependencies": {
29
28
  "react": "^18.3.1"
@@ -31,6 +30,7 @@
31
30
  "devDependencies": {
32
31
  "@types/node": "^20.0.0",
33
32
  "@vitejs/plugin-react": "4.6.0",
33
+ "@hubspot/cms-dev-server": "^1.0.0",
34
34
  "typescript": "^5.0.0"
35
35
  },
36
36
  "author": "content-assets",
@@ -1,63 +0,0 @@
1
- import { ChoiceField, NumberField } from '@hubspot/cms-components/fields';
2
- import { ContentFieldsProps } from './types.js';
3
-
4
- const ContentFields = ({
5
- orientationLabel = 'Orientation',
6
- orientationName = 'orientation',
7
- orientationDefault = 'horizontal',
8
- alignmentLabel = 'Alignment',
9
- alignmentName = 'alignment',
10
- alignmentDefault = 'stretch',
11
- lengthLabel = 'Length',
12
- lengthName = 'length',
13
- lengthDefault = 100,
14
- thicknessLabel = 'Thickness',
15
- thicknessName = 'thickness',
16
- thicknessDefault = 1,
17
- }: ContentFieldsProps) => {
18
- return (
19
- <>
20
- <ChoiceField
21
- label={orientationLabel}
22
- name={orientationName}
23
- required={true}
24
- choices={[
25
- ['horizontal', 'Horizontal'],
26
- ['vertical', 'Vertical'],
27
- ]}
28
- default={orientationDefault}
29
- />
30
- <ChoiceField
31
- label={alignmentLabel}
32
- name={alignmentName}
33
- required={true}
34
- choices={[
35
- ['stretch', 'Stretch'],
36
- ['start', 'Start'],
37
- ['center', 'Center'],
38
- ['end', 'End'],
39
- ]}
40
- default={alignmentDefault}
41
- />
42
- <NumberField
43
- label={lengthLabel}
44
- name={lengthName}
45
- required={true}
46
- suffix="%"
47
- min={1}
48
- max={100}
49
- default={lengthDefault}
50
- />
51
- <NumberField
52
- label={thicknessLabel}
53
- name={thicknessName}
54
- required={true}
55
- suffix="px"
56
- min={1}
57
- default={thicknessDefault}
58
- />
59
- </>
60
- );
61
- };
62
-
63
- export default ContentFields;