mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-06 06:07:33 +02:00
Merge pull request #103 from phuoc-ng/stick-table-column
Add stick table column
This commit is contained in:
@@ -66,6 +66,7 @@ enum Pattern {
|
||||
StickyFooter = 'Sticky footer',
|
||||
StickyHeader = 'Sticky header',
|
||||
StickySections = 'Sticky sections',
|
||||
StickyTableColumn = 'Sticky table column',
|
||||
StickyTableHeaders = 'Sticky table headers',
|
||||
Switch = 'Switch',
|
||||
Tab = 'Tab',
|
||||
|
@@ -168,6 +168,7 @@ const ExplorePage = () => {
|
||||
<CoverCard pattern={Pattern.Ribbon} />
|
||||
<CoverCard pattern={Pattern.Separator} />
|
||||
<CoverCard pattern={Pattern.StackedCards} />
|
||||
<CoverCard pattern={Pattern.StickyTableColumn} />
|
||||
<CoverCard pattern={Pattern.StickyTableHeaders} />
|
||||
<CoverCard pattern={Pattern.Timeline} />
|
||||
<CoverCard pattern={Pattern.VideoBackground} />
|
||||
|
@@ -10,9 +10,9 @@ const Details: React.FC<{}> = () => {
|
||||
const [value, setValue] = useState(0);
|
||||
const decrease = () => setValue(value - 1);
|
||||
const increase = () => setValue(value + 1);
|
||||
const change = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = parseInt(e.target.value, 10);
|
||||
const newValue = isNaN(value) ? 0 : value;
|
||||
const change = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const v = parseInt(e.target.value, 10);
|
||||
const newValue = isNaN(v) ? 0 : v;
|
||||
setValue(newValue);
|
||||
};
|
||||
|
||||
|
@@ -43,6 +43,7 @@ const Details: React.FC<{}> = () => {
|
||||
source={`
|
||||
<div>
|
||||
<header style="
|
||||
/* Stick to the top */
|
||||
position: sticky;
|
||||
top: 0;
|
||||
">
|
||||
@@ -56,7 +57,11 @@ const Details: React.FC<{}> = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<RelatedPatterns patterns={[Pattern.StickyTableHeaders]} />
|
||||
<RelatedPatterns
|
||||
patterns={[
|
||||
Pattern.StickySections, Pattern.StickyTableColumn, Pattern.StickyTableHeaders,
|
||||
]}
|
||||
/>
|
||||
</DetailsLayout>
|
||||
);
|
||||
};
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import { Helmet } from 'react-helmet';
|
||||
|
||||
import RelatedPatterns from '../../components/RelatedPatterns';
|
||||
import Pattern from '../../constants/Pattern';
|
||||
import DetailsLayout from '../../layouts/DetailsLayout';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
|
||||
@@ -62,7 +64,7 @@ const Details: React.FC<{}> = () => {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
/* Stick at the top */
|
||||
/* Stick to the top */
|
||||
position: sticky;
|
||||
top: 0;
|
||||
">
|
||||
@@ -75,6 +77,8 @@ const Details: React.FC<{}> = () => {
|
||||
`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<RelatedPatterns patterns={[Pattern.StickyHeader, Pattern.StickyTableColumn, Pattern.StickyTableHeaders]} />
|
||||
</DetailsLayout>
|
||||
);
|
||||
};
|
||||
|
77
client/patterns/sticky-table-column/Cover.tsx
Normal file
77
client/patterns/sticky-table-column/Cover.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import React from 'react';
|
||||
|
||||
import Frame from '../../placeholders/Frame';
|
||||
import Line from '../../placeholders/Line';
|
||||
import Rectangle from '../../placeholders/Rectangle';
|
||||
|
||||
const Cover: React.FC<{}> = () => {
|
||||
return (
|
||||
<Frame>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<table
|
||||
style={{
|
||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
||||
borderCollapse: 'collapse',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
{
|
||||
Array(3).fill(0).map((_, index) => {
|
||||
return (
|
||||
<th
|
||||
key={index}
|
||||
style={{
|
||||
backgroundColor: index === 0 ? 'rgba(0, 0, 0, 0.1)' : '',
|
||||
padding: '6px 4px',
|
||||
}}
|
||||
>
|
||||
{index === 0 ? <Rectangle /> : <Line />}
|
||||
</th>
|
||||
);
|
||||
})
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
Array(2).fill(0).map((_, row) => {
|
||||
return (
|
||||
<tr key={row} style={{ borderTop: '1px solid rgba(0, 0, 0, 0.3)' }}>
|
||||
{
|
||||
Array(3).fill(0).map((__, col) => {
|
||||
return (
|
||||
<td
|
||||
key={col}
|
||||
style={{
|
||||
backgroundColor: col === 0 ? 'rgba(0, 0, 0, 0.1)' : '',
|
||||
padding: '6px 4px',
|
||||
}}
|
||||
>
|
||||
{col === 0 ? <Rectangle /> : <Line />}
|
||||
</td>
|
||||
);
|
||||
})
|
||||
}
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Frame>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cover;
|
151
client/patterns/sticky-table-column/Details.tsx
Normal file
151
client/patterns/sticky-table-column/Details.tsx
Normal file
@@ -0,0 +1,151 @@
|
||||
// tslint:disable:prefer-object-spread
|
||||
import React from 'react';
|
||||
import { Helmet } from 'react-helmet';
|
||||
|
||||
import RelatedPatterns from '../../components/RelatedPatterns';
|
||||
import Pattern from '../../constants/Pattern';
|
||||
import DetailsLayout from '../../layouts/DetailsLayout';
|
||||
import Block from '../../placeholders/Block';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
import Rectangle from '../../placeholders/Rectangle';
|
||||
|
||||
const Details: React.FC<{}> = () => {
|
||||
const numberOfColumns = 10;
|
||||
return (
|
||||
<DetailsLayout title="Sticky table column">
|
||||
<Helmet>
|
||||
<meta name="description" content="Create sticky table column with CSS" />
|
||||
<meta name="keywords" content="css position sticky, css sticky table column" />
|
||||
</Helmet>
|
||||
<div style={{ padding: '64px 32px' }}>
|
||||
<div style={{ lineHeight: 1.5, marginBottom: '16px' }}>
|
||||
Try to scroll the main content of table horizontally to see the first column sticks to the left.
|
||||
</div>
|
||||
<BrowserFrame
|
||||
content={(
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
||||
height: '400px',
|
||||
overflow: 'auto',
|
||||
width: '60%',
|
||||
}}
|
||||
>
|
||||
<table
|
||||
style={{
|
||||
borderCollapse: 'collapse',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
{
|
||||
Array(numberOfColumns).fill(0).map((_, index) => {
|
||||
return (
|
||||
<th
|
||||
key={index}
|
||||
style={
|
||||
Object.assign({}, {
|
||||
padding: '16px',
|
||||
}, index === 0 ? {
|
||||
backgroundColor: '#ddd',
|
||||
left: 0,
|
||||
position: 'sticky',
|
||||
} : {},
|
||||
)}
|
||||
>
|
||||
<div style={{ width: '200px' }}>
|
||||
{
|
||||
index === 0
|
||||
? <Rectangle />
|
||||
: <Block numberOfBlocks={3} />
|
||||
}
|
||||
</div>
|
||||
</th>
|
||||
);
|
||||
})
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
Array(10).fill(0).map((_, row) => {
|
||||
return (
|
||||
<tr key={row} style={{ borderTop: '1px solid rgba(0, 0, 0, 0.3)' }}>
|
||||
{
|
||||
Array(numberOfColumns).fill(0).map((__, col) => {
|
||||
return (
|
||||
<td
|
||||
key={col}
|
||||
style={
|
||||
Object.assign({}, {
|
||||
padding: '16px',
|
||||
}, col === 0 ? {
|
||||
backgroundColor: '#ddd',
|
||||
left: 0,
|
||||
position: 'sticky',
|
||||
} : {},
|
||||
)}
|
||||
>
|
||||
{
|
||||
col === 0
|
||||
? <Rectangle />
|
||||
: <Block numberOfBlocks={3} />
|
||||
}
|
||||
</td>
|
||||
);
|
||||
})
|
||||
}
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
source={`
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="
|
||||
/* Background color */
|
||||
background-color: #ddd;
|
||||
|
||||
/* Stick to the left */
|
||||
left: 0;
|
||||
position: sticky;
|
||||
|
||||
/* Displayed on top of other rows when scrolling */
|
||||
z-index: 9999;
|
||||
">
|
||||
...
|
||||
</th>
|
||||
|
||||
<!-- Repeat other header column ... -->
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<RelatedPatterns patterns={[Pattern.StickyHeader, Pattern.StickySections, Pattern.StickyTableHeaders]} />
|
||||
</DetailsLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
@@ -45,7 +45,7 @@ const Details: React.FC<{}> = () => {
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<thead style={{ }}>
|
||||
<thead>
|
||||
<tr>
|
||||
{
|
||||
Array(3).fill(0).map((_, index) => {
|
||||
@@ -98,9 +98,9 @@ const Details: React.FC<{}> = () => {
|
||||
/* Background color */
|
||||
background-color: #ddd;
|
||||
|
||||
/* Sticky to the top */
|
||||
/* Stick to the top */
|
||||
position: sticky;
|
||||
top: 0px;
|
||||
top: 0;
|
||||
|
||||
/* Displayed on top of other rows when scrolling */
|
||||
z-index: 9999;
|
||||
@@ -118,7 +118,11 @@ const Details: React.FC<{}> = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<RelatedPatterns patterns={[Pattern.StickyHeader]} />
|
||||
<RelatedPatterns
|
||||
patterns={[
|
||||
Pattern.StickyHeader, Pattern.StickySections, Pattern.StickyTableColumn,
|
||||
]}
|
||||
/>
|
||||
</DetailsLayout>
|
||||
);
|
||||
};
|
||||
|
@@ -67,6 +67,7 @@
|
||||
<url><loc>https://csslayout.io/patterns/sticky-footer</loc></url>
|
||||
<url><loc>https://csslayout.io/patterns/sticky-header</loc></url>
|
||||
<url><loc>https://csslayout.io/patterns/sticky-sections</loc></url>
|
||||
<url><loc>https://csslayout.io/patterns/sticky-table-column</loc></url>
|
||||
<url><loc>https://csslayout.io/patterns/sticky-table-headers</loc></url>
|
||||
<url><loc>https://csslayout.io/patterns/switch</loc></url>
|
||||
<url><loc>https://csslayout.io/patterns/tab</loc></url>
|
||||
|
Reference in New Issue
Block a user