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(ImageBasePositionedComponent): add subcomponent to positioning component in Image #7166

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1621520
feat(ImageBasePositionedComponent): add subcomponent to positioning c…
EldarMuhamethanov Jul 10, 2024
9844cbd
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Jul 10, 2024
2bdca6d
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Jul 16, 2024
07b86ea
feat(ImageBasePositionedComponent): add placement to position component
EldarMuhamethanov Jul 16, 2024
029571d
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Jul 16, 2024
5aba85c
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Jul 17, 2024
0b0237f
fix(ImageBasePositionedComponent): add horizontal and vertical indent…
EldarMuhamethanov Jul 17, 2024
82269e2
feat(ImageBasePositionedComponent): add 2xs and 4xl size of indent
EldarMuhamethanov Jul 17, 2024
a23447e
fix(ImageBasePositionedComponent): rewrite calculate indent logic
EldarMuhamethanov Jul 21, 2024
f03330d
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Jul 22, 2024
47a41a9
fix(ImageBaseFloatElement): rename component
EldarMuhamethanov Jul 22, 2024
ebf6926
fix(ImageBaseFloatElement): fix test
EldarMuhamethanov Jul 22, 2024
de6a7e0
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Aug 7, 2024
2f3ec3c
fix: rename PositionedComponent to FloatElement
EldarMuhamethanov Aug 8, 2024
3cba881
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Aug 12, 2024
9cee169
fix(ImageBaseFloatElement): remove containerRef props and rename 'on-…
EldarMuhamethanov Aug 13, 2024
1a15e9a
fix(ImageBaseFloatElement): fix tests
EldarMuhamethanov Aug 13, 2024
0ce252b
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Aug 27, 2024
57a7753
fix(ImageBaseFloatElement): rename props vertical and horizontal inde…
EldarMuhamethanov Aug 27, 2024
cc7d574
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Sep 13, 2024
e7e5822
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Sep 16, 2024
537bc0e
Merge branch 'master' into e.muhamethanov/6924/image-overlay-components
EldarMuhamethanov Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/vkui/src/components/Image/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ const WithPositionedComponents = () => {
<Image size={96} src={getAvatarUrl('app_shorm_online')} alt="Приложение шторм онлайн">
{showContextMenu && (
<Image.PositionedComponent
position={{
insetInlineEnd: '5%',
insetBlockStart: '5%',
}}
position="top-end"
horizontalIndent="l"
verticalIndent="l"
visibility={contextMenuOpened ? 'always' : contextMenuVisibility}
>
<ContextMenu onShownChange={setContextMenuOpened} />
Expand Down
2 changes: 2 additions & 0 deletions packages/vkui/src/components/ImageBase/ImageBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ImageBaseOverlay, type ImageBaseOverlayProps } from './ImageBaseOverlay
import {
ImageBasePositionedComponent,
type ImageBasePositionedComponentProps,
type PositionedComponentIndentation,
type PositionedComponentPlacement,
type PositionedComponentPosition,
} from './ImageBasePositionedComponent/ImageBasePositionedComponent';
Expand All @@ -27,6 +28,7 @@ export type {
ImageBasePositionedComponentProps,
PositionedComponentPlacement,
PositionedComponentPosition,
PositionedComponentIndentation,
};

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,105 @@
inset-inline-end: var(--vkui_internal--PositionedComponent_inset_inline_end, initial);
inset-block-start: var(--vkui_internal--PositionedComponent_inset_block_start, initial);
inset-block-end: var(--vkui_internal--PositionedComponent_inset_block_end, initial);

--vkui_internal--PositionedComponent_horizontal_indent: 0;
--vkui_internal--PositionedComponent_vertical_indent: 0;
}

.PositionedComponent--horizontalIndent-xs {
--vkui_internal--PositionedComponent_horizontal_indent: var(--vkui--spacing_size_xs);
}

.PositionedComponent--horizontalIndent-s {
--vkui_internal--PositionedComponent_horizontal_indent: var(--vkui--spacing_size_s);
}

.PositionedComponent--horizontalIndent-m {
--vkui_internal--PositionedComponent_horizontal_indent: var(--vkui--spacing_size_m);
}

.PositionedComponent--horizontalIndent-l {
--vkui_internal--PositionedComponent_horizontal_indent: var(--vkui--spacing_size_l);
}

.PositionedComponent--horizontalIndent-xl {
--vkui_internal--PositionedComponent_horizontal_indent: var(--vkui--spacing_size_xl);
}

.PositionedComponent--horizontalIndent-2xl {
--vkui_internal--PositionedComponent_horizontal_indent: var(--vkui--spacing_size_2xl);
}

.PositionedComponent--horizontalIndent-3xl {
--vkui_internal--PositionedComponent_horizontal_indent: var(--vkui--spacing_size_3xl);
}

.PositionedComponent--verticalIndent-xs {
--vkui_internal--PositionedComponent_vertical_indent: var(--vkui--spacing_size_xs);
}

.PositionedComponent--verticalIndent-s {
--vkui_internal--PositionedComponent_vertical_indent: var(--vkui--spacing_size_s);
}

.PositionedComponent--verticalIndent-m {
--vkui_internal--PositionedComponent_vertical_indent: var(--vkui--spacing_size_m);
}

.PositionedComponent--verticalIndent-l {
--vkui_internal--PositionedComponent_vertical_indent: var(--vkui--spacing_size_l);
}

.PositionedComponent--verticalIndent-xl {
--vkui_internal--PositionedComponent_vertical_indent: var(--vkui--spacing_size_xl);
}

.PositionedComponent--verticalIndent-2xl {
--vkui_internal--PositionedComponent_vertical_indent: var(--vkui--spacing_size_2xl);
}

.PositionedComponent--verticalIndent-3xl {
--vkui_internal--PositionedComponent_vertical_indent: var(--vkui--spacing_size_3xl);
}

.PositionedComponent--hidden {
opacity: 0;
}

.PositionedComponent--position-topStart {
inset-inline-start: 0;
inset-block-start: 0;
inset-inline-start: var(--vkui_internal--PositionedComponent_horizontal_indent);
inset-block-start: var(--vkui_internal--PositionedComponent_vertical_indent);
}

.PositionedComponent--position-top {
inset-inline-start: 50%;
inset-block-start: 0;
inset-block-start: var(--vkui_internal--PositionedComponent_vertical_indent);
transform: translateX(-50%);
}

.PositionedComponent--position-topEnd {
inset-inline-end: 0;
inset-block-start: 0;
inset-inline-end: var(--vkui_internal--PositionedComponent_horizontal_indent);
inset-block-start: var(--vkui_internal--PositionedComponent_vertical_indent);
}

.PositionedComponent--position-bottomStart {
inset-inline-start: 0;
inset-block-end: 0;
inset-inline-start: var(--vkui_internal--PositionedComponent_horizontal_indent);
inset-block-end: var(--vkui_internal--PositionedComponent_vertical_indent);
}

.PositionedComponent--position-bottom {
inset-inline-start: 50%;
inset-block-end: 0;
inset-block-end: var(--vkui_internal--PositionedComponent_vertical_indent);
transform: translateX(-50%);
}

.PositionedComponent--position-bottomEnd {
inset-block-end: 0;
inset-inline-end: 0;
inset-block-end: var(--vkui_internal--PositionedComponent_vertical_indent);
inset-inline-end: var(--vkui_internal--PositionedComponent_horizontal_indent);
}

.PositionedComponent--position-middleStart {
inset-inline-start: 0;
inset-inline-start: var(--vkui_internal--PositionedComponent_horizontal_indent);
inset-block-start: 50%;
transform: translateY(-50%);
}
Expand All @@ -57,7 +116,7 @@
}

.PositionedComponent--position-middleEnd {
inset-inline-end: 0;
inset-inline-end: var(--vkui_internal--PositionedComponent_horizontal_indent);
inset-block-start: 50%;
transform: translateY(-50%);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { baselineComponent } from '../../../testing/utils';
import { Image } from '../../Image/Image';
import {
ImageBasePositionedComponent,
PositionedComponentIndentation,
PositionedComponentPlacement,
} from './ImageBasePositionedComponent';
import styles from './ImageBasePositionedComponent.module.css';
Expand Down Expand Up @@ -88,6 +89,46 @@ describe(ImageBasePositionedComponent, () => {
expect(screen.getByTestId('component')).toHaveClass(styles['PositionedComponent--hidden']);
});

it('check visibility on image hover without use Image', async () => {
const containerRef: React.RefObject<HTMLDivElement> = {
current: null,
};
render(
<>
<div ref={containerRef}>
<ImageBasePositionedComponent
data-testid="component"
visibility="on-image-hover"
containerRef={containerRef}
position="top"
/>
</div>
</>,
);

expect(screen.getByTestId('component')).toHaveClass(styles['PositionedComponent--hidden']);

fireEvent(
containerRef.current!,
new MouseEvent('mouseover', {
bubbles: true,
cancelable: true,
}),
);

expect(screen.getByTestId('component')).not.toHaveClass(styles['PositionedComponent--hidden']);

fireEvent(
containerRef.current!,
new MouseEvent('mouseout', {
bubbles: true,
cancelable: true,
}),
);

expect(screen.getByTestId('component')).toHaveClass(styles['PositionedComponent--hidden']);
});

const placementFixtures = Object.entries({
'top-start': styles['PositionedComponent--position-topStart'],
'top': styles['PositionedComponent--position-top'],
Expand All @@ -107,4 +148,102 @@ describe(ImageBasePositionedComponent, () => {
render(<ImageBasePositionedComponent data-testid="component" position={placement} />);
expect(screen.getByTestId('component')).toHaveClass(className);
});

const horizontalIndentationFixtures = Object.entries({
'xs': styles['PositionedComponent--horizontalIndent-xs'],
's': styles['PositionedComponent--horizontalIndent-s'],
'm': styles['PositionedComponent--horizontalIndent-m'],
'l': styles['PositionedComponent--horizontalIndent-l'],
'xl': styles['PositionedComponent--horizontalIndent-xl'],
'2xl': styles['PositionedComponent--horizontalIndent-2xl'],
'3xl': styles['PositionedComponent--horizontalIndent-3xl'],
}).map(([indent, className]) => ({
indent: indent as Exclude<PositionedComponentIndentation, string | number>,
className,
}));

it.each(horizontalIndentationFixtures)(
'should have horizontal indentation className %j',
({ indent, className }) => {
render(
<ImageBasePositionedComponent
data-testid="component"
position="top"
horizontalIndent={indent}
/>,
);
expect(screen.getByTestId('component')).toHaveClass(className);
},
);

const verticalIndentationFixtures = Object.entries({
'xs': styles['PositionedComponent--verticalIndent-xs'],
's': styles['PositionedComponent--verticalIndent-s'],
'm': styles['PositionedComponent--verticalIndent-m'],
'l': styles['PositionedComponent--verticalIndent-l'],
'xl': styles['PositionedComponent--verticalIndent-xl'],
'2xl': styles['PositionedComponent--verticalIndent-2xl'],
'3xl': styles['PositionedComponent--verticalIndent-3xl'],
}).map(([indent, className]) => ({
indent: indent as Exclude<PositionedComponentIndentation, string | number>,
className,
}));

it.each(verticalIndentationFixtures)(
'should have vertical indentation className %j',
({ indent, className }) => {
render(
<ImageBasePositionedComponent
data-testid="component"
position="top"
verticalIndent={indent}
/>,
);
expect(screen.getByTestId('component')).toHaveClass(className);
},
);

it('check number indentation', () => {
render(
<ImageBasePositionedComponent
data-testid="component"
position="top"
verticalIndent={10}
horizontalIndent={15}
/>,
);
expect(
screen
.getByTestId('component')
.style.getPropertyValue('--vkui_internal--PositionedComponent_horizontal_indent'),
).toBe('15px');

expect(
screen
.getByTestId('component')
.style.getPropertyValue('--vkui_internal--PositionedComponent_vertical_indent'),
).toBe('10px');
});

it('check string indentation', () => {
render(
<ImageBasePositionedComponent
data-testid="component"
position="top"
verticalIndent="5%"
horizontalIndent="10%"
/>,
);
expect(
screen
.getByTestId('component')
.style.getPropertyValue('--vkui_internal--PositionedComponent_horizontal_indent'),
).toBe('10%');

expect(
screen
.getByTestId('component')
.style.getPropertyValue('--vkui_internal--PositionedComponent_vertical_indent'),
).toBe('5%');
});
});
Loading