@ndlib/component-library 1.0.5 → 1.0.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.
@@ -22,6 +22,14 @@ const headlinedCards = [
22
22
  width: '500px',
23
23
  },
24
24
  },
25
+ {
26
+ headline: 'Paws, Hooves, Fins & Feathers',
27
+ image: 'https://strapi-prod-library-website-contentbucket52d4b12c-1whgwwl6746tz.s3.us-east-1.amazonaws.com/RBSC_Spring2020_Rep_2_a88660826b.jpg',
28
+ size: CARD_SIZE.SM,
29
+ sx: {
30
+ width: '500px',
31
+ },
32
+ },
25
33
  {
26
34
  headline: 'Tracy C. Bergstrom, director of the Specialized Collection Services Program',
27
35
  image: 'https://strapi-prod-library-website-contentbucket52d4b12c-1whgwwl6746tz.s3.us-east-1.amazonaws.com/Tracy_News_218x275_1dd180dc80.jpg',
@@ -1,6 +1,6 @@
1
+ import React from 'react';
1
2
  import { StyledElementProps, StylesProp } from '../../../theme';
2
3
  import { COLOR } from '../../../theme/colors';
3
- import React from 'react';
4
4
  export declare enum CARD_LAYOUT {
5
5
  VERTICAL = "vertical",
6
6
  HORIZONTAL = "horizontal"
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useEffect, useState } from 'react';
2
3
  import { HEADING_SIZE, Heading } from '../../elements/text/Heading';
3
4
  import { ReadMore } from '../../elements/text/ReadMore';
4
5
  import { useTheme } from '../../../theme';
@@ -7,7 +8,6 @@ import { Box } from '../../elements/layout/Box';
7
8
  import { Icon } from '../../elements/Icon';
8
9
  import { Column, FONT, FONT_SIZE, Row, TYPOGRAPHY_TYPE } from '../../..';
9
10
  import { COLOR } from '../../../theme/colors';
10
- import React, { useEffect, useState } from 'react';
11
11
  import { KEY_CODES } from '../../../utils/misc';
12
12
  import { useHover } from '../../../utils/hooks/useHover';
13
13
  export var CARD_LAYOUT;
@@ -58,11 +58,26 @@ export const Card = ({ size, displayDate, headline, image, alt, layout, onClick,
58
58
  const isVertical = !layout || layout === CARD_LAYOUT.VERTICAL;
59
59
  const { isHovered, anchorElementProps } = useHover();
60
60
  const [activeBackground, setActiveBackground] = useState(isHovered ? COLOR.ND_SKY_BLUE : COLOR.BACKGROUND);
61
- const imageHeight = imageHeightProp || (isVertical ? 'auto' : '100%');
62
- const imageWidth = imageWidthProp || (isVertical ? '100%' : 'auto');
61
+ const [objectFit, setObjectFit] = useState('scale-down');
63
62
  useEffect(() => {
64
63
  setActiveBackground(isHovered ? COLOR.ND_SKY_BLUE : COLOR.BACKGROUND);
65
64
  }, [isHovered]);
65
+ useEffect(() => {
66
+ if (image) {
67
+ const img = new Image();
68
+ img.onload = () => {
69
+ if (img.width > img.height) {
70
+ setObjectFit('contain');
71
+ }
72
+ else {
73
+ setObjectFit('scale-down');
74
+ }
75
+ };
76
+ img.src = image;
77
+ }
78
+ }, [image]);
79
+ const imageHeight = imageHeightProp || (isVertical ? 'auto' : '100%');
80
+ const imageWidth = imageWidthProp || (isVertical ? '100%' : 'auto');
66
81
  const contentPaddingY = isVertical ? contentPaddingX : 2;
67
82
  const typography = size === CARD_SIZE.SM
68
83
  ? TYPOGRAPHY_TYPE.HEADLINE_SMALL
@@ -90,7 +105,7 @@ export const Card = ({ size, displayDate, headline, image, alt, layout, onClick,
90
105
  } }, { children: _jsx("img", { src: image, alt: alt, style: {
91
106
  width: imageWidth,
92
107
  height: imageHeight,
93
- objectFit: 'scale-down',
108
+ objectFit: objectFit,
94
109
  } }) }))), displayDate && _jsx(DateDisplay, { date: displayDate }), heading && (_jsxs(Row, Object.assign({ sx: Object.assign({ bg: COLOR.PRIMARY, color: COLOR.WHITE, width: '100%', px: contentPaddingX, py: 3, justifyContent: 'space-between', alignItems: 'center' }, headingStyles) }, { children: [_jsxs(Row, { children: [headingIcon && (_jsx(Icon, { icon: headingIcon, size: FONT_SIZE.LG, color: COLOR.WHITE, sx: { mr: 2 } })), _jsx(Heading, Object.assign({ size: HEADING_SIZE.SM, sx: {
95
110
  color: COLOR.WHITE,
96
111
  mt: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [