How to use @sitecore-jss/sitecore-jss - 8 common examples

To help you get started, we’ve selected a few @sitecore-jss/sitecore-jss examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sitecore / jss / packages / sitecore-jss-react-native / src / components / Image.tsx View on Github external
if (height) {
    imgStyles.height = typeof height !== 'number' ? Number(height) : height;
  }

  // react native styles/StyleSheets can be merged by passing them as an array to the native Image component
  newAttrs.style = style ? [imgStyles, style] : imgStyles;

  // in react-native, you need to "import" static assets via `require` statements
  // when the packager builds your app, it (presumably) statically analyzes your code, extracts
  // the assets that are `require`d into an array/map, then assigns them a numerical value.
  if (typeof src === 'number') {
    newAttrs.source = src;
  } else {
    // assume we have a "network image", i.e. something loaded via http(s)
    // update image URL for jss handler and image rendering params
    const uri = mediaApi.updateImageUrl(src, imageUrlParams);
    // for network images, the "source" prop is an object with at least "uri" value, e.g. { uri: 'http://aviato.com/myimg.jpg' }
    newAttrs.source = { uri };
  }

  return newAttrs;
};
github Sitecore / jss / packages / sitecore-jss-angular / src / components / image.directive.ts View on Github external
private getImageAttrs(fieldAttrs: any, parsedAttrs: any, imageParams: any): any {
    const combinedAttrs = {
      ...fieldAttrs,
      ...parsedAttrs,
    };
    // tslint:disable-next-line:prefer-const
    let { src, srcSet, ...otherAttrs } = combinedAttrs;
    if (!src) {
      return null;
    }
    const newAttrs = {
      ...otherAttrs,
    };
    // update image URL for jss handler and image rendering params
    src = mediaApi.updateImageUrl(src, imageParams);
    if (srcSet) {
      // replace with HTML-formatted srcset, including updated image URLs
      newAttrs.srcSet = mediaApi.getSrcSet(src, srcSet, imageParams);
    } else {
      newAttrs.src = src;
    }
    return newAttrs;
  }
github Sitecore / jss / packages / sitecore-jss-react / src / components / Image.tsx View on Github external
src: string;
    srcSet: any;
    otherAttrs: any[];
  },
  imageParams: any
) => {
  if (!src) {
    return null;
  }

  const newAttrs: any = {
    ...otherAttrs,
  };

  // update image URL for jss handler and image rendering params
  const resolvedSrc = mediaApi.updateImageUrl(src, imageParams);
  if (srcSet) {
    // replace with HTML-formatted srcset, including updated image URLs
    newAttrs.srcSet = mediaApi.getSrcSet(resolvedSrc, srcSet, imageParams);
  } else {
    newAttrs.src = resolvedSrc;
  }
  return newAttrs;
};
github Sitecore / jss / packages / sitecore-jss-angular / src / components / image.directive.ts View on Github external
...fieldAttrs,
      ...parsedAttrs,
    };
    // tslint:disable-next-line:prefer-const
    let { src, srcSet, ...otherAttrs } = combinedAttrs;
    if (!src) {
      return null;
    }
    const newAttrs = {
      ...otherAttrs,
    };
    // update image URL for jss handler and image rendering params
    src = mediaApi.updateImageUrl(src, imageParams);
    if (srcSet) {
      // replace with HTML-formatted srcset, including updated image URLs
      newAttrs.srcSet = mediaApi.getSrcSet(src, srcSet, imageParams);
    } else {
      newAttrs.src = src;
    }
    return newAttrs;
  }
github Sitecore / jss / packages / sitecore-jss-react / src / components / Image.tsx View on Github external
},
  imageParams: any
) => {
  if (!src) {
    return null;
  }

  const newAttrs: any = {
    ...otherAttrs,
  };

  // update image URL for jss handler and image rendering params
  const resolvedSrc = mediaApi.updateImageUrl(src, imageParams);
  if (srcSet) {
    // replace with HTML-formatted srcset, including updated image URLs
    newAttrs.srcSet = mediaApi.getSrcSet(resolvedSrc, srcSet, imageParams);
  } else {
    newAttrs.src = resolvedSrc;
  }
  return newAttrs;
};
github Sitecore / jss / packages / sitecore-jss-react / src / components / Image.tsx View on Github external
...otherProps
}) => {
  // allows the mistake of using 'field' prop instead of 'media' (consistent with other helpers)
  if (field && !media) {
    media = field;
  }

  const dynamicMedia: any = media;

  if (!media || (!dynamicMedia.editable && !dynamicMedia.value && !dynamicMedia.src)) {
    return null;
  }

  // we likely have an experience editor value, should be a string
  if (editable && dynamicMedia.editable) {
    const foundImg = mediaApi.findEditorImageTag(dynamicMedia.editable);
    if (!foundImg) {
      return getEditableWrapper(dynamicMedia.editable);
    }

    const foundImgProps = convertAttributesToReactProps(foundImg.attrs);
    // Note: otherProps may override values from foundImgProps, e.g. `style`, `className` prop
    // We do not attempt to merge.
    const imgAttrs = getImageAttrs({ ...foundImgProps, ...otherProps } as any, imageParams);
    if (!imgAttrs) {
      return getEditableWrapper(dynamicMedia.editable);
    }

    const imgHtml = ReactDOMServer.renderToStaticMarkup(<img>);
    const editableMarkup = dynamicMedia.editable.replace(foundImg.imgTag, imgHtml);
    return getEditableWrapper(editableMarkup);
  }
github Sitecore / jss / packages / sitecore-jss-angular / src / components / image.directive.ts View on Github external
private updateView() {
    const overrideAttrs = {
      ...this.getElementAttrs(),
      ...this.attrs,
    };
    const media = this.field;

    if (!media || (!media.editable && !media.value && !media.src)) {
      return;
    }

    let attrs: any = {};

    // we likely have an experience editor value, should be a string
    if (this.editable && media.editable) {
      const foundImg = mediaApi.findEditorImageTag(media.editable);
      if (!foundImg) {
        return this.renderInlineWrapper(media.editable);
      }
      attrs = this.getImageAttrs(foundImg.attrs, overrideAttrs, this.urlParams);
      if (!attrs) {
        return this.renderInlineWrapper(media.editable);
      }
      const tempImg: HTMLImageElement = this.renderer.createElement('img');
      Object.entries(attrs).forEach(([key, attrValue]: [string, any]) =>
        tempImg.setAttribute(key, attrValue)
      );
      const editableMarkup = media.editable.replace(foundImg.imgTag, tempImg.outerHTML);
      return this.renderInlineWrapper(editableMarkup);
    }

    // some wise-guy/gal is passing in a 'raw' image object value
github Sitecore / jss / samples / basic-sample-angular / sitecore / definitions / data.ts View on Github external
export const getRouteData = (route) => {
  switch (route) {
    case '/': {
      return convertRouteToLayoutServiceFormat(routes.home);
    }
  }
};

@sitecore-jss/sitecore-jss

This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains the core JSS APIs (layout service) and utilities.

Apache-2.0
Latest version published 29 days ago

Package Health Score

84 / 100
Full package analysis

Similar packages