Skip to content

Commit b11ae01

Browse files
Merge branch 'support-slds-2' into support-slds-2-form-element-field-set
2 parents 004d394 + afd0bc4 commit b11ae01

File tree

12 files changed

+249
-145
lines changed

12 files changed

+249
-145
lines changed

src/scripts/MediaObject.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,23 @@ import classnames from 'classnames';
77
export type MediaObjectProps = {
88
figureLeft?: ReactNode;
99
figureRight?: ReactNode;
10-
figureCenter?: ReactNode;
10+
centered?: boolean;
1111
children?: ReactNode;
1212
} & HTMLAttributes<HTMLDivElement>;
1313

1414
/**
1515
*
1616
*/
1717
export const MediaObject: FC<MediaObjectProps> = (props) => {
18-
const {
19-
className,
20-
figureLeft,
21-
figureRight,
22-
figureCenter,
23-
children,
24-
...rprops
25-
} = props;
26-
const mediaClassNames = classnames('slds-media', className);
18+
const { className, figureLeft, figureRight, centered, children, ...rprops } =
19+
props;
20+
const mediaClassNames = classnames(
21+
'slds-media',
22+
{ 'slds-media_center': centered },
23+
className
24+
);
2725
return (
2826
<div className={mediaClassNames} {...rprops}>
29-
{figureCenter ? (
30-
<div className='slds-media__figure'>{figureCenter}</div>
31-
) : undefined}
3227
{figureLeft ? (
3328
<div className='slds-media__figure'>{figureLeft}</div>
3429
) : undefined}

src/scripts/Modal.tsx

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,30 @@
1-
import React, {
2-
HTMLAttributes,
3-
CSSProperties,
4-
FC,
5-
createContext,
6-
useContext,
7-
useMemo,
8-
ReactNode,
9-
} from 'react';
1+
import React, { HTMLAttributes, CSSProperties, FC, ReactNode } from 'react';
102
import classnames from 'classnames';
113
import { Button } from './Button';
4+
import { Text } from './Text';
125
import { useEventCallback } from './hooks';
136

14-
/**
15-
*
16-
*/
17-
const ModalHandlersContext = createContext<{
18-
onHide?: () => void;
19-
}>({});
20-
217
/**
228
*
239
*/
2410
export type ModalHeaderProps = {
2511
className?: string;
2612
title?: string;
2713
tagline?: string;
28-
closeButton?: boolean;
29-
onClose?: () => void;
3014
};
3115

3216
/**
3317
*
3418
*/
3519
export const ModalHeader: FC<ModalHeaderProps> = (props) => {
36-
const {
37-
className,
38-
title,
39-
tagline,
40-
closeButton,
41-
onClose: onClose_,
42-
...rprops
43-
} = props;
44-
const { onHide: onHideModal } = useContext(ModalHandlersContext);
45-
const onClose = useEventCallback(() => {
46-
onClose_?.();
47-
onHideModal?.();
48-
});
20+
const { className, title, tagline, ...rprops } = props;
4921
const hdClassNames = classnames(className, 'slds-modal__header');
5022
return (
5123
<div className={hdClassNames} {...rprops}>
52-
<h2 className='slds-text-heading_medium'>{title}</h2>
24+
<Text tag='h2' category='heading' type='medium' tabIndex={-1}>
25+
{title}
26+
</Text>
5327
{tagline ? <p className='slds-m-top_x-small'>{tagline}</p> : null}
54-
{closeButton ? (
55-
<Button
56-
type='icon-inverse'
57-
className='slds-modal__close'
58-
icon='close'
59-
iconSize='large'
60-
alt='Close'
61-
inverse
62-
onClick={onClose}
63-
/>
64-
) : null}
6528
</div>
6629
);
6730
};
@@ -128,6 +91,8 @@ export type ModalProps = {
12891
opened?: boolean;
12992
containerStyle?: CSSProperties;
13093
onHide?: () => void;
94+
closeButton?: boolean;
95+
onClose?: () => void;
13196
} & HTMLAttributes<HTMLDivElement>;
13297

13398
/**
@@ -141,6 +106,8 @@ const Modal_: FC<ModalProps> = (props) => {
141106
size,
142107
containerStyle,
143108
onHide,
109+
closeButton,
110+
onClose: onClose_,
144111
...rprops
145112
} = props;
146113
const modalClassNames = classnames(className, 'slds-modal', {
@@ -150,21 +117,37 @@ const Modal_: FC<ModalProps> = (props) => {
150117
const backdropClassNames = classnames(className, 'slds-backdrop', {
151118
'slds-backdrop_open': opened,
152119
});
153-
const handlers = useMemo(() => ({ onHide }), [onHide]);
120+
const onClose = useEventCallback(() => {
121+
onClose_?.();
122+
onHide?.();
123+
});
154124
return (
155-
<ModalHandlersContext.Provider value={handlers}>
156-
<div
125+
<>
126+
<section
157127
className={modalClassNames}
158128
aria-hidden={!opened}
159129
role='dialog'
130+
tabIndex={-1}
131+
aria-modal='true'
160132
{...rprops}
161133
>
162134
<div className='slds-modal__container' style={containerStyle}>
135+
{closeButton ? (
136+
<Button
137+
type='icon'
138+
className='slds-modal__close'
139+
icon='close'
140+
iconSize='large'
141+
alt='Close'
142+
inverse
143+
onClick={onClose}
144+
/>
145+
) : null}
163146
{children}
164147
</div>
165-
</div>
166-
<div className={backdropClassNames} />
167-
</ModalHandlersContext.Provider>
148+
</section>
149+
<div className={backdropClassNames} role='presentation' />
150+
</>
168151
);
169152
};
170153

src/scripts/Popover.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, {
44
FC,
55
ReactNode,
66
forwardRef,
7+
useId,
78
useEffect,
89
} from 'react';
910
import classnames from 'classnames';
@@ -70,13 +71,13 @@ export type PopoverProps = {
7071
bodyStyle?: CSSProperties;
7172
offsetX?: number;
7273
offsetY?: number;
73-
} & HTMLAttributes<HTMLDivElement>;
74+
} & HTMLAttributes<HTMLElement>;
7475

7576
/**
7677
*
7778
*/
7879
export const PopoverInner = forwardRef<
79-
HTMLDivElement,
80+
HTMLElement,
8081
PopoverProps & AutoAlignInjectedProps
8182
>((props, ref) => {
8283
const {
@@ -117,16 +118,20 @@ export const PopoverInner = forwardRef<
117118
: undefined
118119
: undefined,
119120
};
121+
const bodyId = useId();
120122
return (
121-
<div
123+
<section
122124
ref={ref}
123125
className={popoverClassNames}
124126
role={tooltip ? 'tooltip' : 'dialog'}
125127
style={rootStyle}
128+
aria-describedby={bodyId}
126129
{...rprops}
127130
>
128-
<PopoverBody style={bodyStyle}>{children}</PopoverBody>
129-
</div>
131+
<PopoverBody id={bodyId} style={bodyStyle}>
132+
{children}
133+
</PopoverBody>
134+
</section>
130135
);
131136
});
132137

src/scripts/Table.tsx

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const TableRow: FC<TableRowProps> = (props) => {
102102
}
103103
const rowClassName = classnames(
104104
className,
105-
header ? 'slds-text-title_caps' : 'slds-hint-parent'
105+
header ? 'slds-line-height_reset' : 'slds-hint-parent'
106106
);
107107
const style = selected
108108
? {
@@ -130,7 +130,7 @@ export type TableHeaderColumnProps = {
130130
sorted?: boolean;
131131
align?: 'left' | 'center' | 'right';
132132
onSort?: () => void;
133-
} & ThHTMLAttributes<HTMLTableHeaderCellElement>;
133+
} & ThHTMLAttributes<HTMLTableCellElement>;
134134

135135
/**
136136
*
@@ -152,7 +152,6 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
152152
const sortable = typeof sortable_ === 'undefined' ? rowSortable : sortable_;
153153
const oClassNames = classnames(
154154
className,
155-
'slds-text-title_caps slds-truncate',
156155
{
157156
'slds-is-sortable': sortable,
158157
'slds-is-resizable': resizable,
@@ -165,8 +164,15 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
165164

166165
const icon = sortDir === 'DESC' ? 'arrowdown' : 'arrowup';
167166

167+
const content = typeof children === 'string' ? children : undefined;
168+
const cellContent = (
169+
<div className='slds-truncate' title={content}>
170+
{children}
171+
</div>
172+
);
173+
168174
return (
169-
<th {...pprops} className={oClassNames} scope='col' style={style}>
175+
<th {...pprops} className={oClassNames} style={style}>
170176
{sortable ? (
171177
<a
172178
onClick={(e) => {
@@ -178,24 +184,18 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
178184
className='slds-th__action slds-text-link_reset'
179185
>
180186
<span className='slds-assistive-text'>Sort </span>
181-
<span className='slds-truncate'>{children}</span>
187+
{cellContent}
182188
<Icon
189+
container
183190
className='slds-is-sortable__icon'
184191
textColor='default'
185-
container
186192
size='x-small'
187193
category='utility'
188194
icon={icon}
189-
style={{ position: 'absolute' }}
190-
/>
191-
<span
192-
className='slds-assistive-text'
193-
aria-live='assertive'
194-
aria-atomic='true'
195195
/>
196196
</a>
197197
) : (
198-
children
198+
cellContent
199199
)}
200200
</th>
201201
);
@@ -207,23 +207,35 @@ export const TableHeaderColumn: FC<TableHeaderColumnProps> = (props) => {
207207
export type TableRowColumnProps = {
208208
width?: string | number;
209209
truncate?: boolean;
210-
} & TdHTMLAttributes<HTMLTableDataCellElement>;
210+
} & TdHTMLAttributes<HTMLTableCellElement>;
211211

212212
/**
213213
*
214214
*/
215215
export const TableRowColumn: FC<TableRowColumnProps> = (props) => {
216-
const { truncate = true, className, width, children, ...pprops } = props;
217-
const oClassNames = classnames(className, {
218-
'slds-truncate': truncate,
219-
});
216+
const {
217+
truncate = true,
218+
className: oClassNames,
219+
width,
220+
children,
221+
...pprops
222+
} = props;
220223
const style: CSSProperties = {};
221224
if (width !== undefined) style.width = width;
222225
if (!truncate) style.position = 'static';
223226

224-
return (
225-
<td role='gridcell' style={style} className={oClassNames} {...pprops}>
227+
const content = typeof children === 'string' ? children : undefined;
228+
const cellContent = truncate ? (
229+
<div className='slds-truncate' title={content}>
226230
{children}
231+
</div>
232+
) : (
233+
children
234+
);
235+
236+
return (
237+
<td style={style} className={oClassNames} {...pprops}>
238+
{cellContent}
227239
</td>
228240
);
229241
};
@@ -274,17 +286,15 @@ export const Table: FC<TableProps> = (props) => {
274286
...rprops
275287
} = props;
276288

277-
const tableClassNames = classnames(
278-
className,
279-
'slds-table slds-table_cell-buffer',
280-
{
281-
'slds-table_bordered': bordered,
282-
'slds-no-row-hover': noRowHover,
283-
'slds-table_striped': striped,
284-
'slds-table_fixed-layout': fixedLayout,
285-
'slds-table_col-bordered': verticalBorders,
286-
}
287-
);
289+
const tableClassNames = classnames(className, 'slds-table', {
290+
'slds-table_bordered': bordered,
291+
'slds-no-row-hover': noRowHover,
292+
'slds-table_striped': striped,
293+
'slds-table_fixed-layout': fixedLayout,
294+
'slds-table_resizable-cols': sortable,
295+
'slds-table_cell-buffer': !sortable,
296+
'slds-table_col-bordered': verticalBorders,
297+
});
288298

289299
const style: CSSProperties = { ...style_ };
290300
if (autoWidth) {

0 commit comments

Comments
 (0)