Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Re-export "ElasticGrid" component #372

Merged
merged 8 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 4 additions & 9 deletions packages/plasma-b2c/api/plasma-b2c.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ import { DsplM } from '@salutejs/plasma-typo';
import { DsplS } from '@salutejs/plasma-typo';
import { Editable } from '@salutejs/plasma-hope';
import { EditableProps } from '@salutejs/plasma-hope';
import { ElasticGrid } from '@salutejs/plasma-hope';
import { ElasticGridProps } from '@salutejs/plasma-hope';
import type { FC } from 'react';
import type { FieldProps } from '@salutejs/plasma-core';
import { FocusProps } from '@salutejs/plasma-core';
Expand Down Expand Up @@ -162,7 +164,6 @@ import { Price } from '@salutejs/plasma-hope';
import { PriceProps } from '@salutejs/plasma-hope';
import { Progress } from '@salutejs/plasma-hope';
import { ProgressProps } from '@salutejs/plasma-hope';
import { PropsWithChildren } from 'react';
import { Radiobox } from '@salutejs/plasma-hope';
import { RadioboxProps } from '@salutejs/plasma-hope';
import { RadioGroup } from '@salutejs/plasma-hope';
Expand Down Expand Up @@ -448,15 +449,9 @@ export { Editable }

export { EditableProps }

// @public
export const ElasticGrid: React_2.FC<PropsWithChildren<ElasticGridProps>>;
export { ElasticGrid }

// @public (undocumented)
export interface ElasticGridProps {
gapX?: number;
gapY?: number;
minColWidth: number;
}
export { ElasticGridProps }

export { FocusProps }

Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion packages/plasma-b2c/src/components/ElasticGrid/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './ElasticGrid';
export { ElasticGrid } from '@salutejs/plasma-hope';
export type { ElasticGridProps } from '@salutejs/plasma-hope';
11 changes: 11 additions & 0 deletions packages/plasma-hope/api/plasma-hope.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import { PinProps } from '@salutejs/plasma-core';
import { Popup } from '@salutejs/plasma-core';
import { PopupProps } from '@salutejs/plasma-core';
import type { PriceProps as PriceProps_2 } from '@salutejs/plasma-core';
import { PropsWithChildren } from 'react';
import { radiuses } from '@salutejs/plasma-core';
import { Ratio } from '@salutejs/plasma-core';
import { default as React_2 } from 'react';
Expand Down Expand Up @@ -585,6 +586,16 @@ export interface EditableProps {
value?: string;
}

// @public
export const ElasticGrid: FC<PropsWithChildren<ElasticGridProps>>;

// @public (undocumented)
export interface ElasticGridProps {
gapX?: number;
gapY?: number;
minColWidth: number;
}

export { extractTextFrom }

export { FocusProps }
Expand Down
6 changes: 6 additions & 0 deletions packages/plasma-hope/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 5 additions & 25 deletions packages/plasma-hope/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,11 @@
"version": "0.10.0",
"description": "Salute Design System / Internal React UI kit for web applications",
"author": "Salute Frontend Team <salute.developers@gmail.com>",
"keywords": [
"design-system",
"react-components",
"ui-kit",
"react"
],
"keywords": ["design-system", "react-components", "ui-kit", "react"],
"main": "index.js",
"module": "es/index.js",
"types": "index.d.ts",
"files": [
"components",
"es",
"hocs",
"hooks",
"mixins",
"tokens",
"types",
"utils",
"index.d.ts",
"index.js"
],
"files": ["components", "es", "hocs", "hooks", "mixins", "tokens", "types", "utils", "index.d.ts", "index.js"],
"repository": {
"type": "git",
"url": "ssh://git@github.com:salute-developers/plasma.git",
Expand Down Expand Up @@ -69,6 +53,7 @@
"@types/node": "16.7.13",
"@types/react": "16.9.38",
"@types/react-dom": "16.9.8",
"@types/resize-observer-browser": "0.1.7",
Yakutoc marked this conversation as resolved.
Show resolved Hide resolved
"@types/styled-components": "5.1.0",
"babel-loader": "8.2.2",
"babel-plugin-annotate-pure-calls": "0.4.0",
Expand Down Expand Up @@ -105,14 +90,9 @@
"test": "jest --passWithNoTests"
},
"typeCoverage": {
"ignoreFiles": [
"src/**/*component-test.tsx",
"src/**/*stories.tsx"
],
"ignoreFiles": ["src/**/*component-test.tsx", "src/**/*stories.tsx"],
"atLeast": 99.96
},
"contributors": [
"Vasiliy Loginevskiy"
],
"contributors": ["Vasiliy Loginevskiy"],
"sideEffects": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import styled from 'styled-components';
import { mount, CypressTestDecorator, PadMe, getComponent } from '@salutejs/plasma-cy-utils';

const Item = styled.div`
width: 100%;
height: 100px;
background-color: #999;
border-radius: 10px;
`;

const items = [
{ id: 0, label: '0' },
Yakutoc marked this conversation as resolved.
Show resolved Hide resolved
{ id: 1, label: '1' },
{ id: 2, label: '2' },
{ id: 3, label: '3' },
{ id: 4, label: '4' },
];

describe('ElasticGrid', () => {
const ElasticGrid = getComponent('ElasticGrid');

before(() => {
cy.on('uncaught:exception', (err) => {
if (err.toString().match(/ResizeObserver loop limit exceeded/)) {
return false;
}
});
});

it('_view', () => {
mount(
<CypressTestDecorator>
<ElasticGrid minColWidth={125} gapX={8} gapY={8}>
{items.map((item) => (
<Item key={item.id}>{item.label}</Item>
))}
</ElasticGrid>
<PadMe />
<ElasticGrid minColWidth={125}>
{items.map((item) => (
<Item key={item.id}>{item.label}</Item>
))}
</ElasticGrid>
</CypressTestDecorator>,
);

cy.matchImageSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PropsWithChildren, useLayoutEffect, useRef, useState } from 'react';
import React, { PropsWithChildren, useLayoutEffect, useRef, useState, FC } from 'react';
import styled from 'styled-components';

const StyledContainer = styled.div`
Expand Down Expand Up @@ -34,7 +34,7 @@ export interface ElasticGridProps {
/**
* Компонент с резиновой сеткой
*/
export const ElasticGrid: React.FC<PropsWithChildren<ElasticGridProps>> = ({
export const ElasticGrid: FC<PropsWithChildren<ElasticGridProps>> = ({
children,
minColWidth,
gapX = 0,
Expand All @@ -56,7 +56,9 @@ export const ElasticGrid: React.FC<PropsWithChildren<ElasticGridProps>> = ({
const currentRef = containerRef.current;

/* istanbul ignore if: убираем проверку на рефы из покрытия */
if (!currentRef) return;
if (!currentRef) {
Yakutoc marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const resizeObserver = new window.ResizeObserver(() => {
const { width } = currentRef.getBoundingClientRect();
Expand Down
1 change: 1 addition & 0 deletions packages/plasma-hope/src/components/ElasticGrid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ElasticGrid';
1 change: 1 addition & 0 deletions packages/plasma-hope/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './components/Carousel';
export * from './components/Cell';
export * from './components/Checkbox';
export * from './components/Editable';
export * from './components/ElasticGrid';
export * from './components/Dropdown';
export * from './components/Grid';
export * from './components/Image';
Expand Down
6 changes: 6 additions & 0 deletions packages/plasma-web/api/plasma-web.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ import { DsplM } from '@salutejs/plasma-typo';
import { DsplS } from '@salutejs/plasma-typo';
import { Editable } from '@salutejs/plasma-hope';
import { EditableProps } from '@salutejs/plasma-hope';
import { ElasticGrid } from '@salutejs/plasma-hope';
import { ElasticGridProps } from '@salutejs/plasma-hope';
import { extractTextFrom } from '@salutejs/plasma-core';
import { FC } from 'react';
import type { FieldProps as FieldProps_2 } from '@salutejs/plasma-core';
Expand Down Expand Up @@ -467,6 +469,10 @@ export { Editable }

export { EditableProps }

export { ElasticGrid }

export { ElasticGridProps }

export { extractTextFrom }

export { FocusProps }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { Story, Meta } from '@storybook/react';
import { InSpacingDecorator, disableProps } from '@salutejs/plasma-sb-utils';
import styled from 'styled-components';

import { ElasticGrid, ElasticGridProps } from '.';

const propsToDisable = ['ref', 'theme', 'as', 'forwardedAs'];

export default {
title: 'Layout/ElasticGrid',
component: ElasticGrid,
argTypes: {
...disableProps(propsToDisable),
},
decorators: [InSpacingDecorator],
} as Meta;

interface ExtraProps {
$width: string;
itemsNumber: number;
}

const StyledElasticGrid = styled(ElasticGrid)<{ $width: string }>`
width: ${({ $width }) => $width};
`;

const Item = styled.div`
width: 100%;
height: 100px;
background-color: #999;
border-radius: 10px;
`;

export const Default: Story<ExtraProps & ElasticGridProps> = ({ itemsNumber, ...props }) => {
return (
<StyledElasticGrid {...props}>
{Array(itemsNumber)
.fill(0)
.map((_, k) => (
<Item key={k} />
))}
</StyledElasticGrid>
);
};

Default.args = {
$width: '600px',
itemsNumber: 5,
minColWidth: 125,
gapX: 8,
gapY: 8,
};
2 changes: 2 additions & 0 deletions packages/plasma-web/src/components/ElasticGrid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ElasticGrid } from '@salutejs/plasma-hope';
export type { ElasticGridProps } from '@salutejs/plasma-hope';
1 change: 1 addition & 0 deletions packages/plasma-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './components/Cell';
export * from './components/Checkbox';
export * from './components/Dropdown';
export * from './components/Editable';
export * from './components/ElasticGrid';
export * from './components/Grid';
export * from './components/Image';
export * from './components/Link';
Expand Down