Skip to content

Commit

Permalink
feat(@dpc-sdp/ripple-ui-core): ✨ support html heading
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingallday committed Sep 5, 2024
1 parent cd987b4 commit c4559b5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
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

0 comments on commit c4559b5

Please sign in to comment.