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(Text): a new component for working with typography #141

Merged
merged 7 commits into from
Jun 16, 2022

Conversation

IsaevAlexandr
Copy link
Contributor

@IsaevAlexandr IsaevAlexandr commented Apr 23, 2022

Hi, this is related to #128

what was done:

  • added Text component;
  • added text and colorText utilities to work with inline classes in existing codebase;
  • removed duplicate code @mixin text-display-3 in styles/mixins.scss;
  • all new entities have the ability to show jsdoc on hover
    Screenshot 2022-04-23 at 17 33 54
    image

also added documentation to storybook

image

@yc-ui-bot
Copy link
Contributor

Preview is ready.

src/components/ColorText/ColorText.scss Outdated Show resolved Hide resolved
src/components/ColorText/ColorText.tsx Outdated Show resolved Hide resolved
src/components/Text/Text.scss Outdated Show resolved Hide resolved
src/components/Text/Text.tsx Outdated Show resolved Hide resolved
src/components/Text/Text.tsx Outdated Show resolved Hide resolved
src/components/Text/Text.tsx Outdated Show resolved Hide resolved
src/components/Text/Text.tsx Outdated Show resolved Hide resolved
src/components/Text/Text.tsx Outdated Show resolved Hide resolved
* <span className={textStyles}>some text</span>
* ```
*/
export const Text: React.FC<TextProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think forfardRef should be added here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to use any type of ref things with this component. If you want to do this just use text utility and certain element.
for example:

const Component = () => {
    const ref = React.useRef<HTMLDivElement>(null);
    return (
        <div ref={ref} className={text()}>
            some text
        </div>
    );
};

The keyword here is explicit usage of ref

src/components/Text/Text.tsx Outdated Show resolved Hide resolved
}) => {
return (
<Tag
className={text({type, ellipsis}, color ? colorText({color}, className) : className)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pass className to colorText

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's useful if you want to add additional class to element. This technic called bem mix

src/components/Text/Text.tsx Outdated Show resolved Hide resolved
src/components/Text/Text.tsx Outdated Show resolved Hide resolved
src/demo/Typography/Typography.tsx Outdated Show resolved Hide resolved
src/components/ColorText/ColorText.tsx Outdated Show resolved Hide resolved
@IsaevAlexandr
Copy link
Contributor Author

/ping

* - inline-2: font-size: 14px; line-height: 16px; font-weight: 400; font-family: var(--yc-font-family-monospace);
* - inline-3: font-size: 16px; line-height: 20px; font-weight: 400; font-family: var(--yc-font-family-monospace);
*/
typography?: typeof TYPOGRAPHY_VARIANTS[number];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it variant?

* - 1: font-size: 28px; line-height: 36px; font-weight: 900;
* - 2: font-size: 32px; line-height: 40px; font-weight: 900;
* - 3: font-size: 40px; line-height: 48px; font-weight: 900;
* - 4: font-size: 48px; line-height: 52px; font-weight: 900;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

font-weight is controlled by variables, and can be changed outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main idea of this comments is ability to quick look at the component and understand what it does. Of course we can override every token of text variant.

I will add note about it in this comment

'code-inline-1',
] as const;

export interface TextBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a props them it should have Props prefix


const b = block('text');

export const TYPOGRAPHY_VARIANTS = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEXT_VARIANTS is better imo, it shows connection to Text component like TEXT_COLORS does.

@@ -0,0 +1,3 @@
export * from './Text';
export {TYPOGRAPHY_VARIANTS, text} from './text/text';
export {TEXT_COLORS, colorText} from './colorText/colorText';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name "not a component or hook or class" files in dash-case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colorText is a component ("block" in BEM paradigm). But yes it's not a "react" component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it's better the entity name and the file name match

Comment on lines +1 to +2
@use '../../variables' as variables;
@use '../../../../styles/mixins' as mixins;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default its already in these namespaces (ns = filename)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed as variables and as mixins;;

@IsaevAlexandr
Copy link
Contributor Author

/fixed

@IsaevAlexandr IsaevAlexandr merged commit 7837ee8 into gravity-ui:main Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants