Skip to content

Commit

Permalink
support for 'auto' alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
indirectlylit committed Dec 17, 2021
1 parent 60bcb4f commit c85e4d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
23 changes: 20 additions & 3 deletions lib/grids/KFixedGridItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>

<div class="grid-item" :class="unitClass" :style="computedStyle">
<div :class="{ debug: gridMetrics.debug, error: !validInputs }">
<div
:class="{ debug: gridMetrics.debug, error: !validInputs }"
:dir="alignment === 'auto' ? 'auto' : null"
>
<!-- @slot Contents of the grid item -->
<slot></slot>
</div>
Expand Down Expand Up @@ -34,8 +37,9 @@
validator: validateSpan,
},
/**
* Horizontal alignment of the item's contents. Can be `'right'`,
* `'left'`, or `'center'`.
* Horizontal alignment of the item's contents. `'left'`, `'right'`,
* and `'center'` will set `text-align`. `'auto'` will set `dir="auto"`
* for user-generated content to support bidirectional text.
*/
alignment: {
type: String,
Expand Down Expand Up @@ -72,6 +76,19 @@
paddingLeft: padding,
paddingRight: padding,
};
// no text-align should be set - handled by dir="auto"
if (this.alignment === 'auto') {
return style;
}
// centered regardless of RTL
if (this.alignment === 'center') {
style.textAlign = 'center';
return style;
}
// handle left and right alignment
let isRtl = this.isRtl;
if (this.gridMetrics && this.gridMetrics.direction) {
isRtl = this.gridMetrics.direction === 'rtl';
Expand Down
5 changes: 3 additions & 2 deletions lib/grids/KGridItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
/**
* Responsive grid item used with KGrid.
*
* Accepts "layout objects" as props, which can define values for 'span',
* Accepts "layout objects" as props, which can define values for 'span',
* 'alignment', or both.
*
* If no span is defined for a particular layout, the item will span the full
* width of the grid.
*
* If no alignment is defined for a particular layout, the item's contents
* will be left-aligned.
* will be left-aligned. Set `alignment` to `'auto'` to set `dir="auto"`
* for user-generated content to support bidirectional text.
*/
export default {
name: 'KGridItem',
Expand Down
4 changes: 2 additions & 2 deletions lib/grids/common.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import log from 'loglevel';

export function validateAlignment(value) {
if (!['right', 'center', 'left'].includes(value)) {
log.error(`If provided, alignment must be one of: 'left', 'right', or 'center'`);
if (!['right', 'center', 'left', 'auto'].includes(value)) {
log.error(`If provided, alignment must be one of: 'left', 'right', 'center', or 'auto`);
return false;
}
return true;
Expand Down

0 comments on commit c85e4d8

Please sign in to comment.