Skip to content

Allow size specific Anchor theme #6643

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

Merged
merged 6 commits into from
Feb 21, 2023
Merged

Allow size specific Anchor theme #6643

merged 6 commits into from
Feb 21, 2023

Conversation

taysea
Copy link
Collaborator

@taysea taysea commented Feb 21, 2023

What does this PR do?

This PR enhances theme.anchor to allow theme.anchor.size[size].color, theme.anchor.size[size].fontWeight, theme.anchor.size[size].textDecoration.

TextContext is necessary because an anchor embedded in text may not receive an explicit size prop but needs to be "size-aware" of the text it is embedded within.

Where should the reviewer start?

src/js/components/Anchor/Anchor.js

What testing has been done on this PR?

Tested local in storybook and added jest tests

Screen Shot 2023-02-21 at 11 17 41 AM

How should this be manually tested?

Local in Size story:

import React from 'react';

import { Anchor, Box, Grommet, Text } from 'grommet';
import { deepMerge } from 'grommet/utils';
import { hpe } from 'grommet-theme-hpe';
import { LinkNext } from 'grommet-icons';

const theme = deepMerge(hpe, {
  anchor: {
    color: 'text-strong',
    textDecoration: 'underline',
    fontWeight: 700,
    size: {
      large: {
        color: 'green!',
        textDecoration: 'none',
      },
      xlarge: {
        color: 'green!',
        textDecoration: 'none',
      },
      xxlarge: {
        color: 'green!',
        textDecoration: 'none',
      },
    },
  },
});

const SizeAnchor = () => (
  <Grommet theme={theme}>
    <Box align="center" pad="large">
      {['xxlarge', 'xlarge', 'large', 'medium', 'small', 'xsmall', '10px'].map(
        (size) => (
          <Box key={size} margin="small">
            <Text size={size}>
              This anchor is <Anchor label={size} href="#" />
            </Text>
          </Box>
        ),
      )}
      {['medium', 'small'].map((size) => (
        <Box key={size} margin="small">
          <Anchor
            size={size}
            label={size || 'default'}
            icon={<LinkNext color="green!" size="18px" />}
            reverse href="#"
          />
        </Box>
      ))}

      <Anchor label="Default" />
    </Box>
  </Grommet>
);

export const Size = () => <SizeAnchor />;

export default {
  title: 'Controls/Anchor/Size',
};

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Closes #6636

Screenshots (if appropriate)

Do the grommet docs need to be updated?

Should this PR be mentioned in the release notes?

Yes. Enhanced Anchor to support size-specific theming.

Is this change backwards compatible or is it a breaking change?

Backwards compatible.

@taysea taysea requested a review from halocline February 21, 2023 22:11
Copy link
Contributor

@ericsoderberghp ericsoderberghp left a comment

Choose a reason for hiding this comment

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

I think we will want to use TextContext within Paragraph as well, in case an Anchor is used there.

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.

Anchor - support size specific theming
3 participants