-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement table cell layout components (#24773)
* feat: Implement table cell layout components Implements table cell layout components from #24762 to break up the aforementioned PR * changefiles
- Loading branch information
Showing
24 changed files
with
515 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-components-5596cfa5-301f-4b16-81ef-f2d953a7f397.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "feat: Export table cell layout components from unstable", | ||
"packageName": "@fluentui/react-components", | ||
"email": "lingfangao@hotmail.com", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-table-563b3e0b-f140-4bac-bcae-d4974090994d.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "feat: Implement table cell layout components", | ||
"packageName": "@fluentui/react-table", | ||
"email": "lingfangao@hotmail.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/TableCellLayout/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-table/src/TableCellPrimaryLayout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/TableCellPrimaryLayout/index'; |
27 changes: 27 additions & 0 deletions
27
...ages/react-components/react-table/src/components/TableCellLayout/TableCellLayout.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { TableCellLayout } from './TableCellLayout'; | ||
import { isConformant } from '../../common/isConformant'; | ||
|
||
describe('TableCellLayout', () => { | ||
isConformant({ | ||
Component: TableCellLayout, | ||
displayName: 'TableCellLayout', | ||
testOptions: { | ||
'has-static-classnames': [ | ||
{ | ||
props: { | ||
media: 'Test Icon', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<TableCellLayout>Default TableCellLayout</TableCellLayout>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-table/src/components/TableCellLayout/TableCellLayout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import { useTableCellLayout_unstable } from './useTableCellLayout'; | ||
import { renderTableCellLayout_unstable } from './renderTableCellLayout'; | ||
import { useTableCellLayoutStyles_unstable } from './useTableCellLayoutStyles'; | ||
import type { TableCellLayoutProps } from './TableCellLayout.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* TableCellLayout component - TODO: add more docs | ||
*/ | ||
export const TableCellLayout: ForwardRefComponent<TableCellLayoutProps> = React.forwardRef((props, ref) => { | ||
const state = useTableCellLayout_unstable(props, ref); | ||
|
||
useTableCellLayoutStyles_unstable(state); | ||
return renderTableCellLayout_unstable(state); | ||
}); | ||
|
||
TableCellLayout.displayName = 'TableCellLayout'; |
17 changes: 17 additions & 0 deletions
17
...ages/react-components/react-table/src/components/TableCellLayout/TableCellLayout.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type TableCellLayoutSlots = { | ||
root: Slot<'div'>; | ||
|
||
media?: Slot<'span'>; | ||
}; | ||
|
||
/** | ||
* TableCellLayout Props | ||
*/ | ||
export type TableCellLayoutProps = ComponentProps<TableCellLayoutSlots> & {}; | ||
|
||
/** | ||
* State used in rendering TableCellLayout | ||
*/ | ||
export type TableCellLayoutState = ComponentState<TableCellLayoutSlots>; |
12 changes: 12 additions & 0 deletions
12
...ts/react-table/src/components/TableCellLayout/__snapshots__/TableCellLayout.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`TableCellLayout renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-TableCellLayout" | ||
> | ||
Default TableCellLayout | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-table/src/components/TableCellLayout/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './TableCellLayout'; | ||
export * from './TableCellLayout.types'; | ||
export * from './renderTableCellLayout'; | ||
export * from './useTableCellLayout'; | ||
export * from './useTableCellLayoutStyles'; |
16 changes: 16 additions & 0 deletions
16
...ges/react-components/react-table/src/components/TableCellLayout/renderTableCellLayout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as React from 'react'; | ||
import { getSlots } from '@fluentui/react-utilities'; | ||
import type { TableCellLayoutState, TableCellLayoutSlots } from './TableCellLayout.types'; | ||
|
||
/** | ||
* Render the final JSX of TableCellLayout | ||
*/ | ||
export const renderTableCellLayout_unstable = (state: TableCellLayoutState) => { | ||
const { slots, slotProps } = getSlots<TableCellLayoutSlots>(state); | ||
|
||
return ( | ||
<slots.root {...slotProps.root}> | ||
{slots.media && <slots.media {...slotProps.media} />} {slotProps.root.children} | ||
</slots.root> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/react-components/react-table/src/components/TableCellLayout/useTableCellLayout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
import { getNativeElementProps, resolveShorthand } from '@fluentui/react-utilities'; | ||
import type { TableCellLayoutProps, TableCellLayoutState } from './TableCellLayout.types'; | ||
|
||
/** | ||
* Create the state required to render TableCellLayout. | ||
* | ||
* The returned state can be modified with hooks such as useTableCellLayoutStyles_unstable, | ||
* before being passed to renderTableCellLayout_unstable. | ||
* | ||
* @param props - props from this instance of TableCellLayout | ||
* @param ref - reference to root HTMLElement of TableCellLayout | ||
*/ | ||
export const useTableCellLayout_unstable = ( | ||
props: TableCellLayoutProps, | ||
ref: React.Ref<HTMLElement>, | ||
): TableCellLayoutState => { | ||
return { | ||
components: { | ||
root: 'div', | ||
media: 'span', | ||
}, | ||
root: getNativeElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
media: resolveShorthand(props.media), | ||
}; | ||
}; |
41 changes: 41 additions & 0 deletions
41
...s/react-components/react-table/src/components/TableCellLayout/useTableCellLayoutStyles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { makeStyles, mergeClasses, shorthands } from '@griffel/react'; | ||
import { tokens } from '@fluentui/react-theme'; | ||
import type { TableCellLayoutSlots, TableCellLayoutState } from './TableCellLayout.types'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
||
export const tableCellLayoutClassNames: SlotClassNames<TableCellLayoutSlots> = { | ||
root: 'fui-TableCellLayout', | ||
media: 'fui-TableCellLayout__media', | ||
}; | ||
|
||
/** | ||
* Styles for the root slot | ||
*/ | ||
const useStyles = makeStyles({ | ||
root: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
...shorthands.gap(tokens.spacingHorizontalS), | ||
...shorthands.flex(1, 1, '0px'), | ||
}, | ||
|
||
media: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
|
||
// TODO add additional classes for different states and/or slots | ||
}); | ||
|
||
/** | ||
* Apply styling to the TableCellLayout slots based on the state | ||
*/ | ||
export const useTableCellLayoutStyles_unstable = (state: TableCellLayoutState): TableCellLayoutState => { | ||
const styles = useStyles(); | ||
state.root.className = mergeClasses(tableCellLayoutClassNames.root, styles.root, state.root.className); | ||
if (state.media) { | ||
state.media.className = mergeClasses(tableCellLayoutClassNames.media, styles.media, state.media.className); | ||
} | ||
|
||
return state; | ||
}; |
28 changes: 28 additions & 0 deletions
28
...ponents/react-table/src/components/TableCellPrimaryLayout/TableCellPrimaryLayout.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { TableCellPrimaryLayout } from './TableCellPrimaryLayout'; | ||
import { isConformant } from '../../common/isConformant'; | ||
import { TableCellPrimaryLayoutProps } from './TableCellPrimaryLayout.types'; | ||
|
||
describe('TableCellPrimaryLayout', () => { | ||
isConformant({ | ||
Component: TableCellPrimaryLayout as React.FC<TableCellPrimaryLayoutProps>, | ||
displayName: 'TableCellPrimaryLayout', | ||
testOptions: { | ||
'has-static-classnames': [ | ||
{ | ||
props: { | ||
media: 'Test Icon', | ||
main: 'Main content', | ||
secondary: 'Secondary content', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
it('renders a default state', () => { | ||
const result = render(<TableCellPrimaryLayout>Default TableCellPrimaryLayout</TableCellPrimaryLayout>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.