Skip to content

Commit

Permalink
feat(PanelHeaderContent): rename status to subtitle (#7781)
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuhamethanov authored Oct 17, 2024
1 parent 70f9eb2 commit b85b8da
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Avatar, PanelHeader, PanelHeaderBack, PanelHeaderButton, PanelHeaderContent } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<PanelHeader
before={<PanelHeaderBack label="Назад" onClick={() => {}} />}
after={
<PanelHeaderButton onClick={() => {}}/>
}
>
<PanelHeaderContent
status="был в сети сегодня, в 18:46"
before={<Avatar size={36} src={'user_va'} />}
>
Влад Анесов
</PanelHeaderContent>
</PanelHeader>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`panel-header-content transforms correctly 1`] = `
"import { Avatar, PanelHeader, PanelHeaderBack, PanelHeaderButton, PanelHeaderContent } from '@vkontakte/vkui';
import React from 'react';
const App = () => {
return (
(<React.Fragment>
<PanelHeader
before={<PanelHeaderBack label="Назад" onClick={() => {}} />}
after={
<PanelHeaderButton onClick={() => {}}/>
}
>
<PanelHeaderContent
subtitle="был в сети сегодня, в 18:46"
before={<Avatar size={36} src={'user_va'} />}
>
Влад Анесов
</PanelHeaderContent>
</PanelHeader>
</React.Fragment>)
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper';

const name = 'panel-header-content';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
18 changes: 18 additions & 0 deletions packages/codemods/src/transforms/v7/panel-header-content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { API, FileInfo } from 'jscodeshift';
import { getImportInfo, renameProp } from '../../codemod-helpers';
import { JSCodeShiftOptions } from '../../types';

export const parser = 'tsx';

export default function transformer(file: FileInfo, api: API, options: JSCodeShiftOptions) {
const { alias } = options;
const j = api.jscodeshift;
const source = j(file.source);
const { localName } = getImportInfo(j, file, 'PanelHeaderContent', alias);

if (localName) {
renameProp(j, source, localName, { status: 'subtitle' });
}

return source.toSource();
}
2 changes: 1 addition & 1 deletion packages/vkui/src/components/PanelHeader/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const Example = () => {
/>
}
>
<PanelHeaderContent before={<Avatar size={36} />} status="Был в сети вчера">
<PanelHeaderContent before={<Avatar size={36} />} subtitle="Был в сети вчера">
Влад Анесов
</PanelHeaderContent>
</PanelHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const PanelHeaderContentPlayground = (props: ComponentPlaygroundProps) =>
propSets={[
{
before: [<Avatar size={36} key="icon" />, undefined],
status: ['Был в сети вчера', undefined],
subtitle: ['Был в сети вчера', undefined],
children: ['Влад Анесов'],
aside: ['Подробнее', undefined],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
block-size: 100%;
}

.status,
.subtitle,
.childrenIn,
.childrenText {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

.status {
.subtitle {
order: 1;
margin-block-start: 1px;
max-inline-size: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Example: Story = {
<PanelHeaderBack onClick={noop} label={platform === 'vkcom' ? 'Назад' : undefined} />
}
>
<PanelHeaderContent before={<Avatar size={36} />} status="Был в сети вчера">
<PanelHeaderContent before={<Avatar size={36} />} subtitle="Был в сети вчера">
Влад Анесов
</PanelHeaderContent>
</PanelHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ const sizeYClassNames = {
export interface PanelHeaderContentProps extends HTMLAttributesWithRootRef<HTMLDivElement> {
aside?: React.ReactNode;
before?: React.ReactNode;
status?: React.ReactNode;
subtitle?: React.ReactNode;
}

interface PanelHeaderChildrenProps extends HasChildren {
hasStatus: boolean;
hasSubtitle: boolean;
hasBefore: boolean;
}

const PanelHeaderChildren = ({ hasStatus, hasBefore, children }: PanelHeaderChildrenProps) => {
const PanelHeaderChildren = ({ hasSubtitle, hasBefore, children }: PanelHeaderChildrenProps) => {
const platform = usePlatform();

return hasStatus || hasBefore ? (
return hasSubtitle || hasBefore ? (
<Text
className={styles.childrenText}
Component="div"
Expand All @@ -54,7 +54,7 @@ const PanelHeaderChildren = ({ hasStatus, hasBefore, children }: PanelHeaderChil
*/
export const PanelHeaderContent = ({
aside,
status,
subtitle,
before,
children,
onClick,
Expand Down Expand Up @@ -90,9 +90,12 @@ export const PanelHeaderContent = ({
{...inProps}
className={classNames(styles.in, !before && platform !== 'android' && styles.inCentered)}
>
{hasReactNode(status) && <Footnote className={styles.status}>{status}</Footnote>}
{hasReactNode(subtitle) && <Footnote className={styles.subtitle}>{subtitle}</Footnote>}
<div className={styles.children}>
<PanelHeaderChildren hasStatus={hasReactNode(status)} hasBefore={hasReactNode(before)}>
<PanelHeaderChildren
hasSubtitle={hasReactNode(subtitle)}
hasBefore={hasReactNode(before)}
>
{children}
</PanelHeaderChildren>
{hasReactNode(aside) && <div className={styles.aside}>{aside}</div>}
Expand Down
2 changes: 1 addition & 1 deletion packages/vkui/src/components/PanelHeaderContent/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Example = () => {
}
>
<PanelHeaderContent
status="был в сети сегодня, в 18:46"
subtitle="был в сети сегодня, в 18:46"
before={<Avatar size={36} src={getAvatarUrl('user_va')} />}
>
Влад Анесов
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b85b8da

Please sign in to comment.