Skip to content

Commit

Permalink
use the Image component so we avoid content redraw
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Jul 6, 2024
1 parent 15bae95 commit 0a6d49f
Show file tree
Hide file tree
Showing 67 changed files with 279 additions and 266 deletions.
41 changes: 31 additions & 10 deletions docs/.vitepress/theme/components/Image.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
<script setup>
import { computed } from 'vue'
import { ref, onMounted, computed } from 'vue'
const props = defineProps({
width: Number,
height: Number,
width: String,
height: String,
alt: String,
src: String,
size: String, // WIDTHxHEIGHT as a string
})
let widthSize, heightSize
const imageIsSmallerThanParent = ref(false)
let widthSize = ref(null)
let heightSize = ref(null)
if (props.size) {
const sizes = props.size.toString().split('x')
widthSize = sizes[0]
heightSize = sizes[1]
widthSize.value = sizes[0]
heightSize.value = sizes[1]
}
const width = computed(() => parseInt(widthSize) || props.width || 0)
const height = computed(() => parseInt(heightSize) || props.height || 0)
const width = computed(() => parseInt(widthSize.value) || parseInt(props.width) || 0)
const height = computed(() => parseInt(heightSize.value) || parseInt(props.height) || 0)
const alt = computed(() => props.alt || 'Avo')
const src = computed(() => props.src || '')
const style = computed(() => `padding-bottom: calc(${height.value}/${width.value} * 100%);`)
const style = computed(() => {
if (imageIsSmallerThanParent.value) {
return `width: ${width.value}px; height: ${height.value}px;`
}
return `padding-bottom: calc(${height.value}/${width.value} * 100%);`
})
const parent = ref(null)
onMounted(() => {
checkParentWidth()
})
const checkParentWidth = () => {
const parentWidth = parent.value.parentNode.getBoundingClientRect().width
const imageWidth = width
imageIsSmallerThanParent.value = parentWidth > imageWidth.value
}
</script>

<template>
<div class="aspect-ratio-box" :style="style">
<div class="aspect-ratio-box" :style="style" ref="parent">
<img :src="src" :alt="alt" loading="lazy" class="aspect-ratio-box-inside">
</div>
</template>
14 changes: 7 additions & 7 deletions docs/3.0/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For example, you might want to mark a user as active/inactive and optionally sen

Once you attach an action to a resource using the `action` method inside the `actions` method, it will appear in the **Actions** dropdown. By default, actions appear on the `Index`, `Show`, and `Edit` views. Versions previous to 2.9 would only display the actions on the `Index` and `Show` views.

![Actions dropdown](/assets/img/actions/actions-dropdown.gif)
<Image src="/assets/img/actions/actions-dropdown.gif" width="710" height="462" alt="Actions dropdown" />
:::info
Since version <Version version="2.13" /> you may use the [customizable controls](./customizable-controls) feature to show the actions outside the dropdown.
:::
Expand Down Expand Up @@ -85,7 +85,7 @@ More about this on the [authorization page](./authorization#attachments).
:::


![Actions](/assets/img/actions/action-fields.jpg)
<Image src="/assets/img/actions/action-fields.jpg" width="711" height="332" alt="Actions" />

## The `handle` method

Expand Down Expand Up @@ -169,7 +169,7 @@ def handle(**args)
end
```

<img :src="('/assets/img/actions/alert-responses.png')" alt="Avo alert responses" class="border inline-block" />
<Image src="/assets/img/actions/alert-responses.png" width="1074" height="558" alt="Avo alert responses" />

### Run actions silently

Expand Down Expand Up @@ -419,7 +419,7 @@ end

You may customize the labels for the action buttons using `confirm_button_label` and `cancel_button_label`.

<img :src="('/assets/img/actions/actions-button-labels.jpg')" alt="Avo button labels" class="border mb-4" />
<Image src="/assets/img/actions/actions-button-labels.jpg" width="699" height="325" alt="Avo button labels" />

### No confirmation actions

Expand Down Expand Up @@ -608,7 +608,7 @@ end
```
:::

![actions link demo](/assets/img/actions/action_link.gif)
<Image src="/assets/img/actions/action_link.gif" width="684" height="391" alt="actions link demo" />

## StimulusJS

Expand All @@ -634,7 +634,7 @@ def actions
action Avo::Actions::Test::CloseModal
end
```
<img :src="('/assets/img/action_divider.png')" class="border mb-4" />
<Image src="/assets/img/action_divider.png" width="306" height="325" alt="" />

:::option `label`
You can pass a `label` option to display that text
Expand All @@ -658,4 +658,4 @@ def actions
end
```

<img :src="('/assets/img/action_icon.png')" class="border mb-4" />
<Image src="/assets/img/action_icon.png" width="306" height="325" alt="" />
2 changes: 1 addition & 1 deletion docs/3.0/associations.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ You might want to change the name that appears on the association page. For exam

You can customize that using [fields localization](i18n.html#localizing-fields).

<img :src="('/assets/img/associations/custom-label.jpg')" alt="Custom label" class="border mb-4" />
<Image src="/assets/img/associations/custom-label.jpg" width="1224" height="692" alt="Custom label" />
12 changes: 6 additions & 6 deletions docs/3.0/associations/belongs_to.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ Controls the creation link visibility on forms.

On the `Index` and `Show` views, Avo will generate a link to the associated record containing the [`self.title`](./../resources.html#setting-the-title-of-the-resource) value of the target resource.

<img :src="('/assets/img/associations/belongs-to-index.jpg')" alt="Belongs to index" class="border mb-4" />
<Image src="/assets/img/associations/belongs-to-index.jpg" width="188" height="115" alt="Belongs to index" />

<img :src="('/assets/img/associations/belongs-to-show.jpg')" alt="Belongs to show" class="border mb-4" />
<Image src="/assets/img/associations/belongs-to-show.jpg" width="531" height="81" alt="Belongs to show" />

On the `Edit` and `New` views, Avo will generate a dropdown element with the available records where the user can change the associated model.

<img :src="('/assets/img/associations/belongs-to-edit.jpg')" alt="Belongs to edit" class="border mb-4" />
<Image src="/assets/img/associations/belongs-to-edit.jpg" width="555" height="123" alt="Belongs to edit" />

## Polymorphic `belongs_to`

Expand Down Expand Up @@ -136,7 +136,7 @@ class Avo::Resources::Comment < Avo::BaseResource
end
```

<img :src="('/assets/img/associations/polymorphic_help.jpg')" alt="Belongs to ploymorphic help" class="border mb-4" />
<Image src="/assets/img/associations/polymorphic_help.jpg" width="1616" height="370" alt="Belongs to ploymorphic help" />

## Searchable `belongs_to`

Expand All @@ -157,8 +157,8 @@ class Avo::Resources::Comment < Avo::BaseResource
end
```

<img :src="('/assets/img/associations/searchable-closed.jpg')" alt="Belongs to searchable" class="border mb-4" />
<img :src="('/assets/img/associations/searchable-open.jpg')" alt="Belongs to searchable" class="border mb-4" />
<Image src="/assets/img/associations/searchable-closed.jpg" width="1232" height="184" alt="Belongs to searchable" />
<Image src="/assets/img/associations/searchable-open.jpg" width="1556" height="1272" alt="Belongs to searchable" />

`searchable` works with `polymorphic` `belongs_to` associations too.

Expand Down
2 changes: 1 addition & 1 deletion docs/3.0/associations/has_many.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You can add use this option to make the association title clickable. That link w

This feature doesn't go deeper than this. It just helps you see the association table easier in a separate page.

![](/assets/img/3_0/has_many/linkable.gif)
<Image src="/assets/img/3_0/has_many/linkable.gif" width="1200" height="875" alt="" />
:::

## Has Many Through
Expand Down
2 changes: 1 addition & 1 deletion docs/3.0/associations/has_one.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `HasOne` association shows the unfolded view of your `has_one` association.
field :admin, as: :has_one
```

<img :src="('/assets/img/associations/has-one.jpg')" alt="Has one" class="border mb-4" />
<Image src="/assets/img/associations/has-one.jpg" width="919" height="824" alt="Has one" />

## Options

Expand Down
18 changes: 9 additions & 9 deletions docs/3.0/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Controls whether the user can see the actions button on the <Index /> page.

Controls whether the user can see the [records reordering](./records-reordering) buttons on the <Index /> page.

<img :src="('/assets/img/authorization/actions_button.jpg')" alt="Actions button" class="border mb-4" />
<Image src="/assets/img/authorization/actions_button.jpg" width="1220" height="632" alt="Actions button" />

:::

Expand Down Expand Up @@ -142,14 +142,14 @@ In the `Post` `has_many` `Comments` example, when you want to authorize `show_co

Controls whether the `Attach comment` button is visible. The `record` variable is the parent record (a `Post` instance in our scenario).

<img :src="('/assets/img/authorization/attach.jpg')" class="border mb-4" />
<Image src="/assets/img/authorization/attach.jpg" width="1224" height="692" alt="" />

:::
:::option `detach_{association}?`

Controls whether the **detach button is available** on the associated record row on the <Index /> view. The `record` variable is the actual row record (a `Comment` instance in our scenario).

<img :src="('/assets/img/authorization/detach.jpg')" class="border mb-4" />
<Image src="/assets/img/authorization/detach.jpg" width="1224" height="692" alt="" />

:::
:::option `view_{association}?`
Expand All @@ -165,7 +165,7 @@ Controls whether the **view button is visible** on the associated record row on
This **does not** control whether the user has access to that record. You control that using the Policy of that record (`PostPolicy.show?` in our example).
:::

<img :src="('/assets/img/authorization/show.jpg')" class="border mb-4" />
<Image src="/assets/img/authorization/show.jpg" width="1224" height="692" alt="" />

:::info Difference between `view_{association}?` and `show_{association}?`
Let's take a `Post` `has_many` `Comment`s.
Expand All @@ -184,28 +184,28 @@ Controls whether the **edit button is visible** on the associated record row on
This **does not** control whether the user has access to that record's edit page. You control that using the Policy of that record (`PostPolicy.show?` in our example).
:::

<img :src="('/assets/img/authorization/edit.jpg')" class="border mb-4" />
<Image src="/assets/img/authorization/edit.jpg" width="1224" height="692" alt="" />

::::
:::option `create_{association}?`

Controls whether the `Create comment` button is visible. The `record` variable is the parent record (a `Post` instance in our scenario).

<img :src="('/assets/img/authorization/create.jpg')" class="border mb-4" />
<Image src="/assets/img/authorization/create.jpg" width="1224" height="692" alt="" />

:::
:::option `destroy_{association}?`

Controls whether the **delete button is visible** on the associated record row on the <Index /> page.The `record` variable is the actual row record (a `Comment` instance in our scenario).

<img :src="('/assets/img/authorization/destroy.jpg')" class="border mb-4" />
<Image src="/assets/img/authorization/destroy.jpg" width="1224" height="692" alt="" />

:::
:::option `act_on_{association}?`

Controls whether the `Actions` dropdown is visible. The `record` variable is the parent record (a `Post` instance in our scenario).

<img :src="('/assets/img/authorization/actions.jpg')" class="border mb-4" />
<Image src="/assets/img/authorization/actions.jpg" width="1224" height="692" alt="" />

:::
:::option `reorder_{association}?`
Expand Down Expand Up @@ -321,7 +321,7 @@ When working with files, it may be necessary to establish policies that determin

Both the `record` and the `user` will be available for you to access.

<img :src="('/assets/img/authorization/file_actions.png')" class="border mb-4 rounded" />
<Image src="/assets/img/authorization/file_actions.png" width="472" height="93" alt="" />

:::option `upload_{FIELD_ID}?`
Controls whether the user can upload the attachment.
Expand Down
10 changes: 5 additions & 5 deletions docs/3.0/basic-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ end

Avo has several types of filters available [Boolean filter](#boolean_filter), [Select filter](#select_filter), [Multiple select filter](#multiple_select_filter) and [Text filter](#text_filter).

<img :src="('/assets/img/filters.png')" alt="Avo filters" style="width: 300px;" class="border mb-4" />
<Image src="/assets/img/filters.png" width="404" height="727" alt="Avo filters" />

### Filter values

Expand Down Expand Up @@ -319,7 +319,7 @@ class Avo::Filters::PostStatus < Avo::Filters::MultipleSelectFilter
end
```

<img :src="('/assets/img/multiple-select-filter.png')" alt="Avo multiple select filter" style="width: 300px;" class="border mb-4" />
<Image src="/assets/img/multiple-select-filter.png" width="404" height="310" alt="Avo multiple select filter" />

### Dynamic options

Expand Down Expand Up @@ -493,7 +493,7 @@ class Avo::Filters::CourseCity < Avo::Filters::BooleanFilter
end
```

<img :src="('/assets/img/filters/dynamic-options.png')" alt="Avo filters" style="width: 300px;" class="border mb-4" />
<Image src="/assets/img/filters/dynamic-options.png" width="688" height="1042" alt="Avo filters" />

The `countries` method above will check if the `Avo::Filters::CourseCountryFilter` has anything selected. If so, get the names of the chosen ones. This way, you show only the cities from the selected countries and not all of them.

Expand Down Expand Up @@ -611,7 +611,7 @@ end
Besides checking if the countries filter is populated (`applied_filters["Avo::Filters::CourseCountryFilter"].present?`), we also want to allow the user to customize the cities filter further, so we need to check if the user has added a value to that filter (`applied_filters["Avo::Filters::CourseCountryFilter"].blank?`).
If these conditions are true, the country filter has a value, and the user hasn't selected any values from the cities filter, we can react to it and set a value as the default one.

<img :src="('/assets/img/filters/dynamic-options.gif')" alt="Avo filters" style="width: 300px;" class="border mb-4" />
<Image src="/assets/img/filters/dynamic-options.gif" width="528" height="800" alt="Avo filters" />

Of course, you can modify the logic and return all kinds of values based on your needs.

Expand All @@ -621,7 +621,7 @@ Of course, you can modify the logic and return all kinds of values based on your

There might be times when you will want to show a message to the user when you're not returning any options. You may customize that message using the `empty_message` option.

<img :src="('/assets/img/filters/empty-message.gif')" alt="Avo filters" style="width: 300px;" class="border mb-4" />
<Image src="/assets/img/filters/empty-message.gif" width="528" height="800" alt="Avo filters" />

```ruby{4}
# app/avo/filters/course_city.rb
Expand Down
10 changes: 5 additions & 5 deletions docs/3.0/branding.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ end

You may also customize the color of Avo's background using the `background` key.

![](/assets/img/branding/green.jpg)
<Image src="/assets/img/branding/green.jpg" width="2560" height="1280" alt="" />

![](/assets/img/branding/red.jpg)
<Image src="/assets/img/branding/red.jpg" width="2560" height="1280" alt="" />

![](/assets/img/branding/orange.jpg)
<Image src="/assets/img/branding/orange.jpg" width="2560" height="1280" alt="" />

:::info
The color format can be hex (starting with `#`) or rgb (three groups split by a space, not a comma).
Expand Down Expand Up @@ -105,7 +105,7 @@ Avo.configure do |config|
end
```

![](/assets/img/branding/chart-colors.jpg)
<Image src="/assets/img/branding/chart-colors.jpg" width="2236" height="1588" alt="" />

:::warning
The chart colors should be hex colors. They are forwarded to chart.js
Expand All @@ -117,7 +117,7 @@ We want to make it easy to change the logo for your app, so we added the `logo`

The `logo` should be the "big" logo you want to display on the desktop version of your app, and `logomark` should be a squared-aspect image that Avo displays on the mobile version.

![](/assets/img/branding/logomark.gif)
<Image src="/assets/img/branding/logomark.gif" width="800" height="572" alt="" />

## Customize the missing image placeholder

Expand Down
Loading

0 comments on commit 0a6d49f

Please sign in to comment.