@hubspot/cms-component-library 0.1.0-alpha.4 → 0.1.0-alpha.6

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.
@@ -2,8 +2,11 @@
2
2
 
3
3
  @layer hscl-library {
4
4
  .button {
5
-
6
5
  @include component-base.hscl-component-conditional('button');
7
6
  @include component-base.hscl-component-hover-conditional('button');
8
7
  }
9
- }
8
+
9
+ .icon {
10
+ fill: var(--hscl-button-color, revert-layer);
11
+ }
12
+ }
@@ -3,11 +3,15 @@
3
3
  import createHsclComponent from '../utils/createHsclComponent.js';
4
4
  import styles from './index.module.scss';
5
5
  import { BaseAndInternalComponentProps } from '../types/index.js';
6
+ import { Icon } from '@hubspot/cms-components';
6
7
 
7
8
  // Base props shared by all variants
8
9
  type BaseButtonProps = BaseAndInternalComponentProps & {
9
10
  disabled?: boolean;
10
11
  children?: React.ReactNode;
12
+ iconFieldPath?: string;
13
+ iconPosition?: 'left' | 'right';
14
+ iconSize?: number;
11
15
  };
12
16
 
13
17
  // Button variant props
@@ -48,10 +52,32 @@ const Component = (props: ButtonProps) => {
48
52
  props: Omit<ButtonVariantProps, 'buttonType' | 'hsclInternal'> &
49
53
  Partial<BaseButtonProps>
50
54
  ) {
51
- const { onClick, disabled = false, children, ...rest } = props;
55
+ const {
56
+ onClick,
57
+ disabled = false,
58
+ children,
59
+ iconPosition = 'right',
60
+ iconFieldPath,
61
+ iconSize = 18,
62
+ ...rest
63
+ } = props;
52
64
  return (
53
65
  <button {...sharedProps} onClick={onClick} disabled={disabled} {...rest}>
66
+ {iconFieldPath && iconPosition === 'left' && (
67
+ <Icon
68
+ fieldPath={iconFieldPath}
69
+ height={iconSize}
70
+ className={styles.icon}
71
+ />
72
+ )}
54
73
  {children}
74
+ {iconFieldPath && iconPosition === 'right' && (
75
+ <Icon
76
+ fieldPath={iconFieldPath}
77
+ height={iconSize}
78
+ className={styles.icon}
79
+ />
80
+ )}
55
81
  </button>
56
82
  );
57
83
  }
@@ -60,10 +86,33 @@ const Component = (props: ButtonProps) => {
60
86
  props: Omit<LinkVariantProps, 'buttonType' | 'hsclInternal'> &
61
87
  Partial<BaseButtonProps>
62
88
  ) {
63
- const { href = '', target = '_self', rel = '', children, ...rest } = props;
89
+ const {
90
+ href = '',
91
+ target = '_self',
92
+ rel = '',
93
+ children,
94
+ iconPosition = 'right',
95
+ iconFieldPath,
96
+ iconSize = 18,
97
+ ...rest
98
+ } = props;
64
99
  return (
65
100
  <a {...sharedProps} href={href} target={target} rel={rel} {...rest}>
101
+ {iconFieldPath && iconPosition === 'left' && (
102
+ <Icon
103
+ fieldPath={iconFieldPath}
104
+ height={iconSize}
105
+ className={styles.icon}
106
+ />
107
+ )}
66
108
  {children}
109
+ {iconFieldPath && iconPosition === 'right' && (
110
+ <Icon
111
+ fieldPath={iconFieldPath}
112
+ height={iconSize}
113
+ className={styles.icon}
114
+ />
115
+ )}
67
116
  </a>
68
117
  );
69
118
  }
@@ -1,5 +1,5 @@
1
- import { LinkField, TextField } from '@hubspot/cms-components/fields'
2
- import __NC__ from './buttonIndex.js';
1
+ import { BooleanField, IconField, LinkField, TextField, IconFieldType, ChoiceField, Visibility } from '@hubspot/cms-components/fields'
2
+ import __NC__ from './index.js';
3
3
 
4
4
  export type __NC__ContentFieldsProps = {
5
5
  buttonTextDefault?: string;
@@ -9,10 +9,26 @@ export type __NC__ContentFieldsProps = {
9
9
  buttonLinkName?: string;
10
10
  buttonLinkDefault?: {url: {type: 'EXTERNAL', content_id: number, href: string}};
11
11
  showButtonLink?: boolean;
12
+ showButtonIcon?: boolean;
13
+ buttonIconLabel?: string;
14
+ buttonIconName?: string;
15
+ buttonIconDefault?: IconFieldType['default'];
16
+ buttonShowIconLabel?: string;
17
+ buttonShowIconName?: string;
18
+ buttonShowIconDefault?: boolean;
19
+ buttonIconPositionLabel?: string;
20
+ buttonIconPositionName?: string;
21
+ buttonIconPositionDefault?: string;
12
22
  }
13
23
 
14
24
  export function contentFields(props: __NC__ContentFieldsProps) {
15
- const { buttonTextDefault, buttonTextLabel, buttonTextName, buttonLinkLabel, buttonLinkName, buttonLinkDefault, showButtonLink = true } = props;
25
+ const { buttonTextDefault, buttonTextLabel, buttonTextName, buttonLinkLabel, buttonLinkName, buttonLinkDefault, showButtonLink = true , buttonShowIconLabel, buttonShowIconName, buttonShowIconDefault, buttonIconLabel, buttonIconName, buttonIconDefault, buttonIconPositionLabel, buttonIconPositionName, buttonIconPositionDefault} = props;
26
+
27
+ const SHOW_ICON_VISIBILITY_RULES: Visibility = {
28
+ operator: 'EQUAL',
29
+ controlling_field: 'showIcon',
30
+ controlling_value_regex: 'true',
31
+ }
16
32
 
17
33
  return (
18
34
  <>
@@ -28,6 +44,26 @@ export function contentFields(props: __NC__ContentFieldsProps) {
28
44
  default={buttonLinkDefault || {url: {type: 'EXTERNAL', content_id: 0, href: 'https://www.google.com'}}}
29
45
  />
30
46
  )}
47
+ <BooleanField
48
+ id="showIcon"
49
+ label={buttonShowIconLabel || 'Show Icon'}
50
+ name={buttonShowIconName || 'showIcon'}
51
+ display='toggle'
52
+ default={buttonShowIconDefault || false}
53
+ />
54
+ <IconField
55
+ label={buttonIconLabel || 'Button Icon'}
56
+ name={buttonIconName || 'buttonIcon'}
57
+ default={buttonIconDefault || {name: 'fa-arrow-right'}}
58
+ visibility={SHOW_ICON_VISIBILITY_RULES}
59
+ />
60
+ <ChoiceField
61
+ label={buttonIconPositionLabel || 'Button Icon Position'}
62
+ name={buttonIconPositionName || 'buttonIconPosition'}
63
+ choices={[['left','Left'], ['right','Right']]}
64
+ default={buttonIconPositionDefault || 'right'}
65
+ visibility={SHOW_ICON_VISIBILITY_RULES}
66
+ />
31
67
  </>
32
68
  )
33
69
  }
@@ -1,14 +1,14 @@
1
- import Button, { ButtonProps } from '@hubspot/cms-component-library/Button';
1
+ import DefaultButton, { ButtonProps as DefaultButtonProps } from '@hubspot/cms-component-library/Button';
2
2
  import { createComponentInstance } from '@hubspot/cms-component-library';
3
3
  import { __NC__ContentFieldsProps, __NC__StyleFieldsProps, contentFields, styleFields } from './fields.js';
4
4
 
5
- export type __NC__Props = ButtonProps & {
5
+ export type __NC__Props = DefaultButtonProps & {
6
6
  variant: 'solid' | 'outline' | 'unstyled';
7
7
  size: 'small' | 'medium' | 'large' | 'xlarge';
8
8
  borderRadius: 'none' | 'small' | 'medium' | 'large' | 'full';
9
9
  };
10
10
 
11
- const __NC__ = createComponentInstance<__NC__Props>(Button)
11
+ const __NC__ = createComponentInstance<__NC__Props>(DefaultButton)
12
12
  .withContentFields<__NC__ContentFieldsProps>(contentFields)
13
13
  .withStyleFields<__NC__StyleFieldsProps>(styleFields);
14
14
 
@@ -47,24 +47,28 @@ __NC__.setDimension('size')
47
47
  .setProps({
48
48
  fontSize: '12px',
49
49
  padding: '12px 16px',
50
+ iconSize: 12,
50
51
  ...sharedSizeProps
51
52
  })
52
53
  .setOption('medium')
53
54
  .setProps({
54
55
  fontSize: '16px',
55
56
  padding: '16px 20px',
57
+ iconSize: 16,
56
58
  ...sharedSizeProps
57
59
  })
58
60
  .setOption('large')
59
61
  .setProps({
60
62
  fontSize: '24px',
61
63
  padding: '20px 24px',
64
+ iconSize: 24,
62
65
  ...sharedSizeProps
63
66
  })
64
67
  .setOption('extraLarge')
65
68
  .setProps({
66
69
  fontSize: '30px',
67
70
  padding: '24px 30px',
71
+ iconSize: 30,
68
72
  ...sharedSizeProps
69
73
  })
70
74
  .createDimensionChoiceField();
@@ -92,4 +96,5 @@ __NC__.setDimension('borderRadius')
92
96
  })
93
97
  .createDimensionChoiceField();
94
98
 
99
+
95
100
  export default __NC__;
@@ -1,13 +1,12 @@
1
- import { createComponentInstance } from '@hubspot/cms-component-library/';
2
- import Heading from '@hubspot/cms-component-library/Heading'
3
- import { HeadingProps } from '@hubspot/cms-component-library/Heading'
1
+ import { createComponentInstance } from '@hubspot/cms-component-library';
2
+ import DefaultHeading, { HeadingProps as DefaultHeadingProps } from '@hubspot/cms-component-library/Heading'
4
3
  import { __NC__ContentFieldsProps, __NC__StyleFieldsProps, contentFields, styleFields } from './fields.js';
5
4
 
6
- export type __NC__Props = HeadingProps & {
5
+ export type __NC__Props = DefaultHeadingProps & {
7
6
  displayAs: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
8
7
  };
9
8
 
10
- export const __NC__ = createComponentInstance<__NC__Props>(Heading)
9
+ const __NC__ = createComponentInstance<__NC__Props>(DefaultHeading)
11
10
  .withContentFields<__NC__ContentFieldsProps>(contentFields)
12
11
  .withStyleFields<__NC__StyleFieldsProps>(styleFields);
13
12
 
@@ -44,3 +43,5 @@ __NC__.setDimension('displayAs')
44
43
  })
45
44
  .createDimensionChoiceField();
46
45
 
46
+ export default Heading
47
+
@@ -0,0 +1,13 @@
1
+ @use '../styles/_component-base';
2
+
3
+ @layer hscl-library {
4
+ .image {
5
+ @include component-base.hscl-component-conditional('image');
6
+ @include component-base.hscl-component-hover-conditional('image');
7
+ }
8
+ .responsive {
9
+ display: var(--hscl-image-display, block);
10
+ max-inline-size: 100%;
11
+ block-size: auto;
12
+ }
13
+ }
@@ -0,0 +1,54 @@
1
+ /* eslint-disable */
2
+
3
+ import createHsclComponent from '../utils/createHsclComponent.js';
4
+ import styles from './index.module.scss';
5
+ import { BaseAndInternalComponentProps } from '../types/index.js';
6
+ import cx from '../utils/classname.js';
7
+
8
+ export type ImageProps = BaseAndInternalComponentProps & {
9
+ src: string;
10
+ alt: string;
11
+ title?: string;
12
+ imgWidth: number; // <img width={imgWidth} /> (html attribute)
13
+ imgHeight: number; // <img height={imgHeight} /> (html attribute)
14
+ loading?: 'lazy' | 'eager' | 'disabled';
15
+ responsive?: boolean;
16
+ };
17
+
18
+ const componentName = 'image';
19
+
20
+ const Component = (props: ImageProps) => {
21
+ const {
22
+ title = '',
23
+ loading = 'lazy',
24
+ imgWidth,
25
+ imgHeight,
26
+ responsive = true,
27
+ hsclInternal: { hsclProcessedClasses, hsclProcessedStyles },
28
+ ...rest
29
+ } = props;
30
+
31
+ const classes = cx(
32
+ hsclProcessedClasses,
33
+ responsive ? styles.responsive : null
34
+ );
35
+
36
+ return (
37
+ <img
38
+ style={hsclProcessedStyles}
39
+ className={classes}
40
+ title={title}
41
+ loading={loading !== 'disabled' ? loading : 'eager'}
42
+ width={imgWidth}
43
+ height={imgHeight}
44
+ {...rest}
45
+ />
46
+ );
47
+ };
48
+
49
+ Component.hsclComponentName = componentName;
50
+ Component.cssModule = styles;
51
+
52
+ const Image = createHsclComponent(Component);
53
+
54
+ export default Image;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-component-library",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "HubSpot CMS React component library for building CMS modules",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./index.ts",