@cloud-ru/uikit-product-site-cards 0.11.3

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +690 -0
  2. package/LICENSE +201 -0
  3. package/README.md +8 -0
  4. package/package.json +51 -0
  5. package/src/components/CardBasic/CardBasic.tsx +74 -0
  6. package/src/components/CardBasic/index.ts +1 -0
  7. package/src/components/CardBasic/styles.module.scss +45 -0
  8. package/src/components/CardBasic/utils.ts +14 -0
  9. package/src/components/CardCase/CardCase.tsx +123 -0
  10. package/src/components/CardCase/index.ts +1 -0
  11. package/src/components/CardCase/styles.module.scss +68 -0
  12. package/src/components/CardInfo/CardInfo.tsx +120 -0
  13. package/src/components/CardInfo/index.ts +1 -0
  14. package/src/components/CardInfo/styles.module.scss +52 -0
  15. package/src/components/CardInfo/utilsTypes.ts +3 -0
  16. package/src/components/CardList/CardList.tsx +90 -0
  17. package/src/components/CardList/index.ts +1 -0
  18. package/src/components/CardList/styles.module.scss +102 -0
  19. package/src/components/CardList/utils.ts +35 -0
  20. package/src/components/CardMarketplace/CardMarketplace.tsx +112 -0
  21. package/src/components/CardMarketplace/index.ts +1 -0
  22. package/src/components/CardMarketplace/styles.module.scss +73 -0
  23. package/src/components/CardMedia/CardMedia.tsx +123 -0
  24. package/src/components/CardMedia/index.ts +1 -0
  25. package/src/components/CardMedia/styles.module.scss +157 -0
  26. package/src/components/CardMedia/types.ts +3 -0
  27. package/src/components/CardMedia/utils.ts +23 -0
  28. package/src/components/CardPartner/CardPartner.tsx +90 -0
  29. package/src/components/CardPartner/index.ts +1 -0
  30. package/src/components/CardPartner/styles.module.scss +60 -0
  31. package/src/components/CardProduct/CardProduct.tsx +123 -0
  32. package/src/components/CardProduct/constants.ts +11 -0
  33. package/src/components/CardProduct/index.ts +1 -0
  34. package/src/components/CardProduct/styles.module.scss +73 -0
  35. package/src/components/index.ts +8 -0
  36. package/src/components/utils.ts +15 -0
  37. package/src/constants.ts +1 -0
  38. package/src/helperComponents/Icon/Icon.tsx +31 -0
  39. package/src/helperComponents/Icon/index.ts +1 -0
  40. package/src/helperComponents/Icon/styles.module.scss +49 -0
  41. package/src/hooks.ts +40 -0
  42. package/src/index.ts +3 -0
@@ -0,0 +1,31 @@
1
+ import { JSXElementConstructor, ReactNode } from 'react';
2
+
3
+ import styles from './styles.module.scss';
4
+
5
+ export type IconElement = JSXElementConstructor<{ size?: number; className?: string }>;
6
+
7
+ export type IconProps = {
8
+ icon: ReactNode | IconElement | { src: string; alt?: string };
9
+ size: 'm' | 'l';
10
+ 'data-test-id'?: string;
11
+ decor?: boolean;
12
+ };
13
+
14
+ const isElementConstructor = (icon: IconProps['icon']): icon is IconElement =>
15
+ typeof icon === 'object' && icon !== null && 'render' in icon;
16
+
17
+ export function Icon({ icon: Icon, size = 'm', 'data-test-id': dataTestId, decor }: IconProps) {
18
+ const isIcon = isElementConstructor(Icon);
19
+ const isImg = !isIcon && typeof Icon === 'object' && Icon !== null && 'src' in Icon;
20
+
21
+ if (isIcon || isImg) {
22
+ return (
23
+ <div className={styles.icon} data-size={size} data-test-id={dataTestId} data-decor={decor || undefined}>
24
+ {isIcon && <Icon />}
25
+ {isImg && <img src={Icon.src} alt={Icon.alt} />}
26
+ </div>
27
+ );
28
+ }
29
+
30
+ return Icon as ReactNode;
31
+ }
@@ -0,0 +1 @@
1
+ export * from './Icon';
@@ -0,0 +1,49 @@
1
+ @use '@sbercloud/figma-tokens-web/build/scss/components/styles-tokens-element' as ste;
2
+
3
+ $decor-padding: 8px;
4
+
5
+ .icon {
6
+ flex-shrink: 0;
7
+ color: ste.$sys-graphite-text-main;
8
+ position: relative;
9
+
10
+ svg, img {
11
+ width: 100% !important; /* stylelint-disable-line declaration-no-important */
12
+ height: 100% !important; /* stylelint-disable-line declaration-no-important */
13
+ }
14
+
15
+ &[data-decor] {
16
+ padding: $decor-padding;
17
+
18
+ & svg, img {
19
+ position: absolute;
20
+ top: 8px;
21
+ left: 8px;
22
+ width: calc(100% - 2 * #{$decor-padding}) !important; /* stylelint-disable-line declaration-no-important */
23
+ height: calc(100% - 2 * #{$decor-padding}) !important; /* stylelint-disable-line declaration-no-important */
24
+ }
25
+
26
+ &:before {
27
+ position: absolute;
28
+ top: 0;
29
+ left: 0;
30
+ content: '';
31
+ display: block;
32
+ width: 100%;
33
+ height: 100%;
34
+ opacity: 50%;
35
+ background-color: ste.$sys-graphite-decor-default;
36
+ border-radius: ste.$radius-icon-predefined-decor-square-m;
37
+ }
38
+ }
39
+
40
+ &[data-size='m'] {
41
+ height: 24px;
42
+ width: 24px;
43
+ }
44
+
45
+ &[data-size='l'] {
46
+ height: 48px;
47
+ width: 48px;
48
+ }
49
+ }
package/src/hooks.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { KeyboardEvent, MouseEvent, MouseEventHandler, useRef } from 'react';
2
+
3
+ import { noop } from './components/utils';
4
+ import { TRIGGER_CLICK_KEY_CODES } from './constants';
5
+
6
+ type useCardInteractionsProps = {
7
+ href?: string;
8
+ disabled?: boolean;
9
+ onClick?: MouseEventHandler<HTMLAnchorElement>;
10
+ };
11
+
12
+ export function useCardInteractions({ href, disabled, onClick }: useCardInteractionsProps) {
13
+ const anchorRef = useRef<HTMLAnchorElement>(null);
14
+
15
+ const handleLinkClick = (e: MouseEvent<HTMLAnchorElement>) => {
16
+ if (disabled) {
17
+ e.preventDefault();
18
+ return;
19
+ }
20
+
21
+ onClick?.(e);
22
+ };
23
+
24
+ const handleCardClick = disabled || !href ? undefined : noop;
25
+
26
+ const handleCardKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
27
+ if (disabled) return;
28
+
29
+ if (TRIGGER_CLICK_KEY_CODES.includes(e.key)) {
30
+ anchorRef?.current?.click();
31
+ }
32
+ };
33
+
34
+ return {
35
+ anchorRef,
36
+ handleLinkClick,
37
+ handleCardClick,
38
+ handleCardKeyDown,
39
+ };
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export * from './hooks';
3
+ export * from './helperComponents/Icon';