Skip to content

Commit 3dfcf30

Browse files
authored
Revert "Remove sx props and Box from Truncate (#6632)" (#6683)
1 parent 3e4b56e commit 3dfcf30

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

.changeset/lucky-facts-obey.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/react/src/ActionList/Description.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const Description: React.FC<React.PropsWithChildren<ActionListDescription
6161
ref={containerRef}
6262
id={inlineDescriptionId}
6363
className={clsx(className, classes.Description)}
64+
sx={sx}
6465
title={effectiveTitle}
6566
inline={true}
6667
maxWidth="100%"

packages/react/src/Truncate/Truncate.docs.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"props": [
2222
{
2323
"name": "maxWidth",
24-
"type": "number | string | (number | string)[]",
24+
"type": "number",
2525
"defaultValue": "125",
2626
"description": "Sets the max-width of the text."
2727
},
@@ -41,6 +41,11 @@
4141
"name": "as",
4242
"type": "React.ElementType",
4343
"defaultValue": "'div'"
44+
},
45+
{
46+
"name": "sx",
47+
"type": "SystemStyleObject",
48+
"deprecated": true
4449
}
4550
],
4651
"subcomponents": []

packages/react/src/Truncate/Truncate.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ Playground.argTypes = {
4141
disable: true,
4242
},
4343
},
44+
sx: {
45+
controls: false,
46+
table: {
47+
disable: true,
48+
},
49+
},
4450
theme: {
4551
controls: false,
4652
table: {

packages/react/src/Truncate/Truncate.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import React from 'react'
22
import {clsx} from 'clsx'
3+
import type {MaxWidthProps} from 'styled-system'
4+
import type {SxProp} from '../sx'
35
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
6+
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
47
import classes from './Truncate.module.css'
58

69
type TruncateProps = React.HTMLAttributes<HTMLElement> & {
710
title: string
811
inline?: boolean
912
expandable?: boolean
10-
maxWidth?: number | string | (number | string)[]
11-
}
13+
} & MaxWidthProps &
14+
SxProp
1215

1316
const Truncate = React.forwardRef(function Truncate(
14-
{as: Component = 'div', children, className, title, inline, expandable, maxWidth = 125, style, ...rest},
17+
{as, children, className, title, inline, expandable, maxWidth = 125, style, sx, ...rest},
1518
ref,
1619
) {
1720
return (
18-
<Component
21+
<BoxWithFallback
1922
{...rest}
2023
ref={ref}
24+
as={as}
2125
className={clsx(className, classes.Truncate)}
2226
data-expandable={expandable}
2327
data-inline={inline}
@@ -29,9 +33,10 @@ const Truncate = React.forwardRef(function Truncate(
2933
typeof maxWidth === 'number' ? `${maxWidth}px` : typeof maxWidth === 'string' ? maxWidth : undefined,
3034
} as React.CSSProperties
3135
}
36+
sx={sx}
3237
>
3338
{children}
34-
</Component>
39+
</BoxWithFallback>
3540
)
3641
}) as PolymorphicForwardRefComponent<'div', TruncateProps>
3742

packages/styled-react/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ exports[`@primer/styled-react exports 1`] = `
44
[
55
"RadioGroup",
66
"ToggleSwitch",
7-
"Truncate",
87
"ActionList",
98
"ActionMenu",
109
"Autocomplete",
@@ -50,6 +49,7 @@ exports[`@primer/styled-react exports 1`] = `
5049
"Timeline",
5150
"Token",
5251
"Tooltip",
52+
"Truncate",
5353
"UnderlineNav",
5454
"Box",
5555
"sx",

packages/styled-react/src/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import {
2-
RadioGroup as PrimerRadioGroup,
3-
Truncate as PrimerTruncate,
4-
ToggleSwitch as PrimerToggleSwitch,
5-
} from '@primer/react'
1+
import {RadioGroup as PrimerRadioGroup, ToggleSwitch as PrimerToggleSwitch} from '@primer/react'
62
import {createStyledComponent} from './utils/createStyledComponent'
73

84
const RadioGroup: ReturnType<typeof createStyledComponent> = /*#__PURE__*/ createStyledComponent(PrimerRadioGroup)
9-
const Truncate: ReturnType<typeof createStyledComponent> = /*#__PURE__*/ createStyledComponent(PrimerTruncate)
105
const ToggleSwitch: ReturnType<typeof createStyledComponent> = /*#__PURE__*/ createStyledComponent(PrimerToggleSwitch)
11-
export {RadioGroup, ToggleSwitch, Truncate}
6+
export {RadioGroup, ToggleSwitch}
127

138
export {
149
ActionList,
@@ -56,6 +51,7 @@ export {
5651
Timeline,
5752
Token,
5853
Tooltip,
54+
Truncate,
5955
UnderlineNav,
6056

6157
// styled-components components or types

0 commit comments

Comments
 (0)