Skip to content

Commit

Permalink
Merge branch 'main' into record-init-clone
Browse files Browse the repository at this point in the history
  • Loading branch information
alexivanenko committed Feb 8, 2024
2 parents b317e36 + f513eb2 commit e56c641
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 15 deletions.
16 changes: 15 additions & 1 deletion packages/oceanfront/src/components/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const OfButton = defineComponent({
density: [String, Number],
disabled: Boolean,
icon: String,
iconPosition: {
type: String,
default: 'start',
},
id: String,
items: [String, Array, Object] as PropType<ItemsProp>,
label: String,
Expand Down Expand Up @@ -166,6 +170,12 @@ export const OfButton = defineComponent({
extraContent,
items && !split ? expand : undefined,
]
const iconPosition = () => {
if (props.iconPosition === 'end') {
return { 'of-flex-reverse': true }
}
return {}
}
return h(
'div',
{
Expand Down Expand Up @@ -196,7 +206,11 @@ export const OfButton = defineComponent({
h(
'button',
{
class: ['of-button-main', scaleClass(props.scale)],
class: [
'of-button-main',
scaleClass(props.scale),
iconPosition(),
],
disabled,
tabindex,
id: buttonId,
Expand Down
49 changes: 48 additions & 1 deletion packages/oceanfront/src/components/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@
</template>

<script lang="ts">
import { ref, defineComponent, computed, watch, Ref } from 'vue'
import {
ref,
defineComponent,
computed,
watch,
Ref,
onMounted,
onUnmounted,
} from 'vue'
import { OfOverlay } from './Overlay'
export default defineComponent({
Expand All @@ -69,6 +77,45 @@ export default defineComponent({
emits: ['update:modelValue'],
setup: function (props, ctx) {
const dialog = ref<any>()
const focusableElements =
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"]'
const handelKeyDown = (e: KeyboardEvent) => {
const firstFocusableElement =
dialog.value.querySelectorAll(focusableElements)[0]
const focusableContent = dialog.value.querySelectorAll(focusableElements)
const lastFocusableElement = focusableContent[focusableContent.length - 1]
let isTabPressed = e.key === 'Tab' || e.keyCode === 9
if (!isTabPressed) {
return
}
if (e.shiftKey) {
if (document.activeElement === firstFocusableElement) {
lastFocusableElement.focus()
e.preventDefault()
}
} else {
if (
document.activeElement === lastFocusableElement ||
!dialog.value.contains(document.activeElement)
) {
firstFocusableElement.focus()
e.preventDefault()
}
}
}
watch(
() => dialog.value,
(value) => {
if (!value) {
document.removeEventListener('keydown', handelKeyDown)
return
}
document.addEventListener('keydown', handelKeyDown)
}
)
onUnmounted(() => {
document.removeEventListener('keydown', handelKeyDown)
})
const dialogHeader: Ref<HTMLDivElement | undefined> = ref()
const active = ref(props.modelValue)
Expand Down
4 changes: 3 additions & 1 deletion packages/oceanfront/src/components/Editable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
@update:model-value="updateValue"
v-model="item.value"
:items="item.items"
:input-type="item.inputType"
:outside="item.outside"
></of-field>
</template>
</template>
Expand Down Expand Up @@ -193,7 +195,7 @@ const OfEditableField = defineComponent({
if (type.value === 'toggle') {
return 'editable'
} else {
return active.value ? 'editable' : 'fixed'
return active.value ? 'editable' : props.modelValue?.mode || 'fixed'
}
})
const resizeInput = (focus = false) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/oceanfront/src/components/TableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ export default defineComponent({
return { coords, depth, fixArrowNext }
}
const mouseMove = (event: MouseEvent | TouchEvent) => {
if (event.cancelable) event.preventDefault()
if (event.cancelable && props.dragInfo?.dragInProgress)
event.preventDefault()
let index = null
let currentDepth = null
if (props.dragInfo?.dragInProgress) {
Expand Down
17 changes: 13 additions & 4 deletions packages/oceanfront/src/components/ToggleInner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ToggleInner = defineComponent({
name: String,
mode: String as PropType<FieldMode>,
scale: [String, Number],
outside: Boolean,
},
emits: ['focus', 'blur', 'inputMounted'],
setup(props, ctx) {
Expand Down Expand Up @@ -65,10 +66,18 @@ export const ToggleInner = defineComponent({
...hooks,
}),
props.switch
? h('div', { class: 'of-switch' }, [
h('div', { class: 'of-switch-track' }),
h('div', { class: 'of-switch-thumb' }),
])
? h(
'div',
{ class: ['of-switch', { outside: !props.outside }] },
[
h('div', {
class: ['of-switch-track', { outside: !props.outside }],
}),
h('div', {
class: ['of-switch-thumb', { outside: !props.outside }],
}),
]
)
: ctx.slots.icon
? ctx.slots.icon(props.checked)
: h(OfIcon, {
Expand Down
2 changes: 1 addition & 1 deletion packages/oceanfront/src/fields/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export const OfTextField = defineComponent({
})
},
fixedContent: () => {
return formatter.value?.formatFixed?.(lazyInputValue) ?? lazyInputValue
return formatter.value?.formatFixed?.(fieldCtx.value) ?? lazyInputValue
},
}

Expand Down
8 changes: 7 additions & 1 deletion packages/oceanfront/src/fields/Toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export const supportedTypes = new Set(['checkbox', 'switch'])

export const OfToggleField = defineComponent({
name: 'OfToggleField',
props: { ...BaseFieldProps, inputType: String, switch: Boolean },
props: {
...BaseFieldProps,
inputType: String,
switch: Boolean,
outside: { type: Boolean, default: true },
},
setup(props, ctx) {
const fieldCtx = provideFieldContext(props, ctx)
const initialValue = computed(() => {
Expand Down Expand Up @@ -88,6 +93,7 @@ export const OfToggleField = defineComponent({
ToggleInner,
{
switch: inputType.value === 'switch',
outside: props.outside,
checked: stateValue.value,
focused: focused.value,
label: fieldCtx.inputLabel,
Expand Down
2 changes: 2 additions & 0 deletions packages/oceanfront/src/lib/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ export const BaseFieldProps = {
formatOptions: null,
defaultValue: null,
sticky: { type: Boolean, default: true },
switch: { type: Boolean, default: false },
outside: { type: Boolean, default: true },
}

export function extendFieldFormat(
Expand Down
4 changes: 3 additions & 1 deletion packages/oceanfront/src/scss/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@
opacity: var(--button-split-opacity);
}
}

.of-flex-reverse {
flex-direction: row-reverse;
}
.of-button-icon,
.of-button-expand {
align-self: center;
Expand Down
21 changes: 18 additions & 3 deletions packages/oceanfront/src/scss/_fields.scss
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,13 @@
transition: left 0.15s ease-in-out, background-color 0.15s ease-in-out;
width: 1em;
}

&-thumb.outside {
left: 0.35em;
top: auto;
width: 0.8em;
height: 0.8em;
background-color: #ffffff;
}
&-track {
border: 1px solid var(--field-color);
border-radius: 1em;
Expand All @@ -801,13 +807,22 @@
height: 100%;
transition: background-color 0.15s ease-in-out, border 0.15s ease-in-out;
}
&-track.outside {
height: 1em;
background-color: #F0F1EE;
border: none;
}
.of--checked & {
.of-switch-thumb {
background-color: var(--of-primary-tint);
.of-switch-thumb{
left: calc(1em - 1px);
}
.of-switch-thumb:not(.outside) {
background-color: var(--of-primary-tint);
}
.of-switch-track {
background-color: var(--of-primary-tint);
}
.of-switch-track:not(.outside) {
opacity: 72%;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/oceanfront/src/scss/_overlay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

.of-dialog-header,
.of-dialog-footer {
max-height: 2em;
max-height: 5em;
line-height: 2em;
width: 100%;
text-align: center;
Expand Down

0 comments on commit e56c641

Please sign in to comment.