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

fix: update align prop value across various components #17834

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 5 additions & 83 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -789,21 +789,7 @@ Map {
},
"CodeSnippet" => Object {
"propTypes": Object {
"align": Object {
"args": Array [
Array [
"top",
"top-left",
"top-right",
"bottom",
"bottom-left",
"bottom-right",
"left",
"right",
],
],
"type": "oneOf",
},
"align": [Function],
"aria-label": Object {
"type": "string",
},
Expand Down Expand Up @@ -1450,25 +1436,7 @@ Map {
],
"type": "oneOf",
},
"tooltipAlignment": Object {
"args": Array [
Array [
"top",
"top-left",
"top-start",
"top-right",
"top-end",
"bottom",
"bottom-left",
"bottom-start",
"bottom-right",
"bottom-end",
"left",
"right",
],
],
"type": "oneOf",
},
"tooltipAlignment": [Function],
"translateWithId": Object {
"type": "func",
},
Expand Down Expand Up @@ -1797,21 +1765,7 @@ Map {
},
"Copy" => Object {
"propTypes": Object {
"align": Object {
"args": Array [
Array [
"top",
"top-left",
"top-right",
"bottom",
"bottom-left",
"bottom-right",
"left",
"right",
],
],
"type": "oneOf",
},
"align": [Function],
"autoAlign": Object {
"type": "bool",
},
Expand All @@ -1837,21 +1791,7 @@ Map {
},
"CopyButton" => Object {
"propTypes": Object {
"align": Object {
"args": Array [
Array [
"top",
"top-left",
"top-right",
"bottom",
"bottom-left",
"bottom-right",
"left",
"right",
],
],
"type": "oneOf",
},
"align": [Function],
"autoAlign": Object {
"type": "bool",
},
Expand Down Expand Up @@ -4240,25 +4180,7 @@ Map {
"IconButton" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"align": Object {
"args": Array [
Array [
"top",
"top-left",
"top-start",
"top-right",
"top-end",
"bottom",
"bottom-left",
"bottom-start",
"bottom-right",
"bottom-end",
"left",
"right",
],
],
"type": "oneOf",
},
"align": [Function],
"autoAlign": Object {
"type": "bool",
},
Expand Down
108 changes: 89 additions & 19 deletions packages/react/src/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,60 @@
import copy from 'copy-to-clipboard';
import deprecate from '../../prop-types/deprecate';
import { usePrefix } from '../../internal/usePrefix';
import deprecateValuesWithin from '../../prop-types/deprecateValuesWithin';

const rowHeightInPixels = 16;
const defaultMaxCollapsedNumberOfRows = 15;
const defaultMaxExpandedNumberOfRows = 0;
const defaultMinCollapsedNumberOfRows = 3;
const defaultMinExpandedNumberOfRows = 16;

export type DeprecatedCodeSnippetAlignment =
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right'
| 'left-bottom'
| 'left-top'
| 'right-bottom'
| 'right-top';

export type NewCodeSnippetAlignmnet =
| 'top'
| 'bottom'
| 'left'
| 'right'
| 'top-start'
| 'top-end'
| 'bottom-start'
| 'bottom-end'
| 'left-end'
| 'left-start'
| 'right-end'
| 'right-start';

export type CodeSnippetAlignment =
| DeprecatedCodeSnippetAlignment
| NewCodeSnippetAlignmnet;
const propMappingFunction = (deprecatedValue) => {
const mapping = {

Check warning on line 62 in packages/react/src/components/CodeSnippet/CodeSnippet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/react/src/components/CodeSnippet/CodeSnippet.tsx#L62

Added line #L62 was not covered by tests
'top-left': 'top-start',
'top-right': 'top-end',
'bottom-left': 'bottom-start',
'bottom-right': 'bottom-end',
'left-bottom': 'left-end',
'left-top': 'left-start',
'right-bottom': 'right-end',
'right-top': 'right-start',
};
return mapping[deprecatedValue];

Check warning on line 72 in packages/react/src/components/CodeSnippet/CodeSnippet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/react/src/components/CodeSnippet/CodeSnippet.tsx#L72

Added line #L72 was not covered by tests
};

export interface CodeSnippetProps {
/**
* Specify how the trigger should align with the tooltip
*/
align?:
| 'top'
| 'top-left'
| 'top-right'
| 'bottom'
| 'bottom-left'
| 'bottom-right'
| 'left'
| 'right';
align?: CodeSnippetAlignment;

/**
* **Experimental**: Will attempt to automatically align the tooltip
Expand Down Expand Up @@ -418,16 +452,52 @@
/**
* Specify how the trigger should align with the tooltip
*/
align: PropTypes.oneOf([
'top',
'top-left',
'top-right',
'bottom',
'bottom-left',
'bottom-right',
'left',
'right',
]),
align: deprecateValuesWithin(
PropTypes.oneOf([
'top',
'top-left', // deprecated use top-start instead
'top-right', // deprecated use top-end instead

'bottom',
'bottom-left', // deprecated use bottom-start instead
'bottom-right', // deprecated use bottom-end instead

'left',
'left-bottom', // deprecated use left-end instead
'left-top', // deprecated use left-start instead

'right',
'right-bottom', // deprecated use right-end instead
'right-top', // deprecated use right-start instead

// new values to match floating-ui
'top-start',
'top-end',
'bottom-start',
'bottom-end',
'left-end',
'left-start',
'right-end',
'right-start',
]),
//allowed prop values
[
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'left',
'left-start',
'left-end',
'right',
'right-start',
'right-end',
],
//optional mapper function
propMappingFunction
),

/**
* Specify a label to be read by screen readers on the containing textbox
Expand Down
75 changes: 61 additions & 14 deletions packages/react/src/components/ComboButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useFeatureFlag } from '../FeatureFlags';
import mergeRefs from '../../tools/mergeRefs';
import { MenuAlignment } from '../MenuButton';
import { TranslateWithId } from '../../types/common';
import deprecateValuesWithin from '../../prop-types/deprecateValuesWithin';

const defaultTranslations = {
'carbon.combo-button.additional-actions': 'Additional actions',
Expand All @@ -36,6 +37,20 @@ const defaultTranslations = {
*/
type TranslationKey = keyof typeof defaultTranslations;

const propMappingFunction = (deprecatedValue) => {
const mapping = {
'top-left': 'top-start',
'top-right': 'top-end',
'bottom-left': 'bottom-start',
'bottom-right': 'bottom-end',
'left-bottom': 'left-end',
'left-top': 'left-start',
'right-bottom': 'right-end',
'right-top': 'right-start',
};
return mapping[deprecatedValue];
};

function defaultTranslateWithId(messageId: string) {
return defaultTranslations[messageId];
}
Expand Down Expand Up @@ -277,20 +292,52 @@ ComboButton.propTypes = {
/**
* Specify how the trigger tooltip should be aligned.
*/
tooltipAlignment: PropTypes.oneOf([
'top',
'top-left',
'top-start',
'top-right',
'top-end',
'bottom',
'bottom-left',
'bottom-start',
'bottom-right',
'bottom-end',
'left',
'right',
]),
tooltipAlignment: deprecateValuesWithin(
PropTypes.oneOf([
'top',
'top-left', // deprecated use top-start instead
'top-right', // deprecated use top-end instead

'bottom',
'bottom-left', // deprecated use bottom-start instead
'bottom-right', // deprecated use bottom-end instead

'left',
'left-bottom', // deprecated use left-end instead
'left-top', // deprecated use left-start instead

'right',
'right-bottom', // deprecated use right-end instead
'right-top', // deprecated use right-start instead

// new values to match floating-ui
'top-start',
'top-end',
'bottom-start',
'bottom-end',
'left-end',
'left-start',
'right-end',
'right-start',
]),
//allowed prop values
[
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'left',
'left-start',
'left-end',
'right',
'right-start',
'right-end',
],
//optional mapper function
propMappingFunction
),

/**
* Optional method that takes in a message id and returns an
Expand Down
Loading
Loading