all files / addon/components/ polaris-text-style.js

100% Statements 4/4
100% Branches 2/2
100% Functions 1/1
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                            10× 10×            
import Component from '@ember/component';
import { computed } from '@ember/object';
import { isEmpty } from '@ember/utils';
import { classify } from '@ember/string';
import layout from '../templates/components/polaris-text-style';
 
/**
 * Polaris text style component.
 * See https://polaris.shopify.com/components/titles-and-text/text-style
 */
export default Component.extend({
  tagName: 'span',
  classNameBindings: ['variationClass'],
 
  layout,
 
  /**
   * Give text additional visual meaning
   *
   * Possible values: positive, negative, strong, subdued
   *
   * @property variation
   * @type {String}
   * @default: null
   * @public
   */
  variation: null,
 
  /**
   * The content that should get the intended styling
   *
   * This component can be used in block form,
   * in which case the block content will be used
   * instead of `text`
   *
   * @property text
   * @type {String}
   * @default: null
   * @public
   */
  text: null,
 
  /*
   * Internal properties.
   */
  variationClass: computed('variation', function() {
    const variation = this.get('variation');
    if (isEmpty(variation)) {
      return null;
    }
 
    return `Polaris-TextStyle--variation${ classify(variation) }`;
  }).readOnly(),
});