Skip to main content
Skip table of contents

Appendix A - Responsive Text Component

Here is an example of how you could create an extension to the standard text component to be able to set font sizes per breakpoint:

CODE
import { css, unsafeCSS } from 'lit-element';
import { FusionText } from '../../../fusion/slide/text';
import { breakpoints } from '../../../../build/config';

const tabletBreakpoint = `${breakpoints.tablet || 1279}px`;
const mobileBreakpoint = `${breakpoints.mobile || 767}px`;

class AntResponsiveText extends FusionText {
  static get properties() {
    const {
      'font-size': fontSize,
      ...rest
    } = super.properties;
    return {
      ...rest,
      'font-size': {
        ...fontSize,
        value: '16px',
      },
      'font-size-tablet': {
        type: String,
        fieldType: 'Number',
        propertyGroup: 'text',
        value: '16px',
        availableUnits: [{ unitType: 'px' }],
      },
      'font-size-mobile': {
        type: String,
        fieldType: 'Number',
        propertyGroup: 'text',
        value: '16px',
        availableUnits: [{ unitType: 'px' }],
      },
    };
  }

  static get options() {
    return {
      ...super.options,
      componentName: 'ant-responsive-text',
      componentUIName: 'Responsive Text',
      componentCategory: 'text',
      componentDescription: 'Component to set font size per breakpoint',
      defaultTemplate: '<p>Default text</p>',
    };
  }

  static get styles() {
    return [
      super.styles,
      this.generateCssProperty('flex-direction'),
      css`
        ::slotted(p) {
          font-size: var(--font-size);
        }
        /* tablet */
        @media only screen and (max-width: ${unsafeCSS(tabletBreakpoint)}) {
          ::slotted(p) {
            font-size: var(--font-size-tablet);
          }
        }
        /* mobile */
        @media only screen and (max-width: ${unsafeCSS(mobileBreakpoint)}) {
          ::slotted(p) {
            font-size: var(--font-size-mobile);
          }
        }
      `,
    ];
  }
}

export { AntResponsiveText };

This component should be added to src/components/slide and then it will be available in the Activator UI.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.