From 5187fbd5d21f50a4b540c7b50e9269ca79f741e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Sat, 21 Nov 2020 23:09:56 +0100 Subject: [PATCH] improve mobile tables --- docs/gridsome.config.js | 24 +++++++++ docs/src/templates/DocPage/style.scss | 71 +++++++++++++++------------ 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/docs/gridsome.config.js b/docs/gridsome.config.js index 0e7d1212..daf72265 100644 --- a/docs/gridsome.config.js +++ b/docs/gridsome.config.js @@ -1,4 +1,5 @@ const path = require('path') +const visit = require('unist-util-visit') function addStyleResource(rule) { rule.use('style-resource') @@ -10,6 +11,28 @@ function addStyleResource(rule) { }) } +function tableWrapper() { + return async tree => { + visit( + tree, + 'table', + (node, index, parent) => { + if (node.type === 'table' && parent.type === 'root') { + const original = { ...node } + + node.type = 'div' + node.children = [original] + node.data = { + hProperties: { + class: 'table-wrapper', + }, + } + } + }, + ) + } +} + module.exports = { siteName: 'tiptap', titleTemplate: '%s | tiptap', @@ -26,6 +49,7 @@ module.exports = { '@gridsome/remark-prismjs', 'remark-container', 'remark-toc', + tableWrapper, ], remark: { autolinkHeadings: { diff --git a/docs/src/templates/DocPage/style.scss b/docs/src/templates/DocPage/style.scss index 71037f4a..f742872b 100644 --- a/docs/src/templates/DocPage/style.scss +++ b/docs/src/templates/DocPage/style.scss @@ -82,7 +82,7 @@ > p code, > ul code, > ol code, - > table code, + > .table-wrapper code, > .remark-container code { color: $colorYellow; background-color: rgba($colorYellow, 0.1); @@ -92,7 +92,7 @@ > p a, > ul a, > ol a, - > table a, + > .table-wrapper a, > .remark-container a { text-decoration: underline; @@ -187,46 +187,55 @@ } } - > table { + > .table-wrapper { + display: block; width: 100%; - border-collapse: collapse; - font-size: 0.85rem; - text-align: left; + overflow-x: auto; + -webkit-overflow-scrolling: touch; - th, - td { - padding: 0.5rem; + > table { + width: 100%; + border-collapse: collapse; + font-size: 0.85rem; + text-align: left; - &:first-child { - padding-left: 0; + th, + td { + padding: 0.5rem; + min-width: 8rem; + + &:first-child { + padding-left: 0; + } + + &:last-child { + padding-right: 0; + } } - &:last-child { - padding-right: 0; + th { + white-space: nowrap; + color: $colorWhite; + font-weight: 500; + border-bottom: 1px solid rgba($colorWhite, 0.2); } - } - th { - color: $colorWhite; - font-weight: 500; - border-bottom: 1px solid rgba($colorWhite, 0.2); - } + td { + border-bottom: 1px solid rgba($colorWhite, 0.1); + } - td { - border-bottom: 1px solid rgba($colorWhite, 0.1); - } - - tr:last-child td { - border-bottom: 0; - } - - tbody tr { - &:last-child td { + tr:last-child td { border-bottom: 0; } - &:hover { - background: rgba($colorWhite, 0.02); + tbody tr { + &:last-child td { + border-bottom: 0; + } + + &:hover { + background: rgba($colorWhite, 0.02); + } } } }