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

[SD-187] Data table html header labels #1316

Merged
merged 1 commit into from
Sep 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ import {
ArgsTable
} from '@storybook/addon-docs'
import RplDataTable from './RplDataTable.vue'
import { RplDataTableColumns, RplDataTableItems, RplDataTableColumnConfig, RplDataTableComplexItems, RplDataTableObjectKeyColumnConfig, RplDataTableObjects, RplDataTableStructuredColumns, RplDataTableStructuredItems, RplDataTableExtraComponents } from './fixtures/sample'
import {
RplDataTableColumns,
RplDataTableItems,
RplDataTableColumnConfig,
RplDataTableComplexItems,
RplDataTableObjectKeyColumnConfig,
RplDataTableObjectKeyColumnHTMLConfig,
RplDataTableObjects,
RplDataTableStructuredColumns,
RplDataTableStructuredItems,
RplDataTableExtraComponents
} from './fixtures/sample'
import { a11yStoryCheck } from './../../../stories/interactions.js'

export const SingleTemplate = (args) => ({
Expand Down Expand Up @@ -124,3 +135,24 @@ export const SingleTemplate = (args) => ({
{SingleTemplate.bind()}
</Story>
</Canvas>

<Canvas>
<Story
name="HTML headings"
play={a11yStoryCheck}
args={{
caption: "Pets II: The Return",
footer: "HTML passed through to headings",
columns: RplDataTableObjectKeyColumnHTMLConfig,
items: RplDataTableExtraComponents,
headingType: {
horizontal: true,
vertical: true
},
showExtraContent: true,
offset: 0
}}
>
{SingleTemplate.bind()}
</Story>
</Canvas>
26 changes: 18 additions & 8 deletions packages/ripple-ui-core/src/components/data-table/RplDataTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<script setup lang="ts">
import { useBreakpoints } from '@vueuse/core'
import { computed, withDefaults, ref, unref, onMounted } from 'vue'
import {
computed,
type ComputedRef,
withDefaults,
ref,
unref,
onMounted
} from 'vue'
import { bpMin } from '../../lib/breakpoints'
import RplDataTableRow, {
extraRowContent,
Expand Down Expand Up @@ -76,13 +83,16 @@ const displayMobileView: ComputedRef<boolean> = computed(() => {
</caption>
<thead v-if="headingType.horizontal && columns.length > 0">
<tr>
<th
v-for="(column, index) in columns"
:key="index"
:class="column.classes"
>
{{ column.label }}
</th>
<template v-for="(column, index) in columns" :key="index">
<th
v-if="column.isLabelHTML"
:class="column.classes"
v-html="column.label"
></th>
<th v-else :class="column.classes">
{{ column.label }}
</th>
</template>
<th v-if="showExtraContent" class="rpl-data-table__actions">
<span class="rpl-u-visually-hidden">Actions</span>
</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type tableColumnConfig = {
component?: string
props?: any
isHTML?: boolean
isLabelHTML?: boolean
}

export type tableRow = {
Expand All @@ -40,7 +41,7 @@ interface Props {
columns: tableColumnConfig[]
items?: Array<string>
row: tableRow
extraContent?: extraRowContent
extraContent?: extraRowContent | null
verticalHeader?: boolean
offset: number
caption?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ export const RplDataTableObjectKeyColumnConfig = [
}
]

export const RplDataTableObjectKeyColumnHTMLConfig = [
{
label: '<em>Nominative descriptor</em>',
objectKey: 'name',
isLabelHTML: true
},
{
label: 'Duration<sup>1</sup>',
objectKey: 'age',
isLabelHTML: true
},
{
label: 'Species',
objectKey: 'type'
}
]

export const RplDataTableObjects = [
{
name: 'George',
Expand Down