all files / addon/components/ polaris-thumbnail.js

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                                                                                                                                 
import Component from '@ember/component';
import { classify } from '@ember/string';
import { computed } from '@ember/object';
import { warn } from '@ember/debug';
import layout from '../templates/components/polaris-thumbnail';
 
const allowedSizes = [
  'small',
  'medium',
  'large'
];
const defaultSize = 'medium';
 
/**
 * Polaris thumbnail component.
 * See https://polaris.shopify.com/components/images-and-icons/thumbnail
 */
export default Component.extend({
  tagName: 'span',
  classNames: ['Polaris-Thumbnail'],
  classNameBindings: ['sizeClass'],
 
  layout,
 
  /**
   * Size of thumbnail
   *
   * @public
   * @property size
   * @type {String}
   * @default: 'medium'
   */
  size: defaultSize,
 
  /**
   * URL for the image
   *
   * @public
   * @property source
   * @type {String}
   * @default: null
   */
  source: null,
 
  /**
   * Alt text for the thumbnail image
   *
   * @public
   * @property alt
   * @type {String}
   * @default: null
   */
  alt: null,
 
  /*
   * Internal properties.
   */
  sizeClass: computed('size', function() {
    let size = this.get('size');
    if (allowedSizes.indexOf(size) === -1) {
      size = defaultSize;
      warn(
        `Unsupported 'size' attribute for 'polaris-thumbnail'. Supported values: ${ allowedSizes.join(', ') }.`,
        { id: 'ember-polaris.polaris-thumbnail.unsupported-size' }
      );
    }
 
    return `Polaris-Thumbnail--size${ classify(size) }`;
  }).readOnly()
});