Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Files] Move <Image /> component to @kbn/shared-ux package #145995

Merged
merged 23 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b8ba04d
initial commit with a lot of boilerplate
jloleysens Nov 22, 2022
489bc87
remove types and hook into base BAZEL build process
jloleysens Nov 22, 2022
c7ffbed
remove image component from files plugin
jloleysens Nov 22, 2022
07c7dc7
added image src to packages
jloleysens Nov 22, 2022
5703bff
updated reference in files example
jloleysens Nov 22, 2022
791621c
create the image "util" package
jloleysens Nov 22, 2022
48f96e0
add image types package
jloleysens Nov 22, 2022
547f37d
added file util package
jloleysens Nov 22, 2022
98bff62
couple of further fixes
jloleysens Nov 22, 2022
fc1a3ed
duplicate story image for now
jloleysens Nov 22, 2022
60dcd6a
created image mocks for the base64d logo
jloleysens Nov 22, 2022
1233ee6
move mock function to mocks folder
jloleysens Nov 22, 2022
461b6e9
Merge branch 'main' into files-move-components-to-packages
jloleysens Nov 22, 2022
84f1aa8
move file image metadata definition to packages
jloleysens Nov 22, 2022
a82d518
update comment and remove build_types directive
jloleysens Nov 22, 2022
c2cb640
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Nov 22, 2022
5929c48
futsing around with types
jloleysens Nov 22, 2022
74b4e59
futsing more with types, fix some nasty issues
jloleysens Nov 22, 2022
dc70c13
update jest config
jloleysens Nov 23, 2022
e3abff2
remove unused jest config
jloleysens Nov 23, 2022
c7a4438
Merge branch 'main' into files-move-components-to-packages
jloleysens Nov 23, 2022
86ff9af
Merge branch 'main' into files-move-components-to-packages
jloleysens Nov 24, 2022
e593b2c
Merge branch 'main' into files-move-components-to-packages
jloleysens Nov 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,10 @@ packages/shared-ux/button/exit_full_screen/types @elastic/kibana-global-experien
packages/shared-ux/card/no_data/impl @elastic/kibana-global-experience
packages/shared-ux/card/no_data/mocks @elastic/kibana-global-experience
packages/shared-ux/card/no_data/types @elastic/kibana-global-experience
packages/shared-ux/file/image/impl @elastic/kibana-global-experience
packages/shared-ux/file/image/mocks @elastic/kibana-global-experience
packages/shared-ux/file/image/types @elastic/kibana-global-experience
packages/shared-ux/file/util @elastic/kibana-global-experience
packages/shared-ux/link/redirect_app/impl @elastic/kibana-global-experience
packages/shared-ux/link/redirect_app/mocks @elastic/kibana-global-experience
packages/shared-ux/link/redirect_app/types @elastic/kibana-global-experience
Expand Down
3 changes: 2 additions & 1 deletion examples/files_example/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

import type { FileKind, FileImageMetadata } from '@kbn/files-plugin/common';
import type { FileKind } from '@kbn/files-plugin/common';
import type { FileImageMetadata } from '@kbn/shared-ux-file-image-types';

export const PLUGIN_ID = 'filesExample';
export const PLUGIN_NAME = 'Files example';
Expand Down
3 changes: 2 additions & 1 deletion examples/files_example/public/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export {
FilesContext,
type ScopedFilesClient,
FilePicker,
Image,
} from '@kbn/files-plugin/public';

export { FileImage as Image } from '@kbn/shared-ux-file-image';

export type { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public';
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@
"@kbn/shared-ux-card-no-data": "link:bazel-bin/packages/shared-ux/card/no_data/impl",
"@kbn/shared-ux-card-no-data-mocks": "link:bazel-bin/packages/shared-ux/card/no_data/mocks",
"@kbn/shared-ux-card-no-data-types": "link:bazel-bin/packages/shared-ux/card/no_data/types",
"@kbn/shared-ux-file-image": "link:bazel-bin/packages/shared-ux/file/image/impl",
"@kbn/shared-ux-file-image-mocks": "link:bazel-bin/packages/shared-ux/file/image/mocks",
"@kbn/shared-ux-file-image-types": "link:bazel-bin/packages/shared-ux/file/image/types",
"@kbn/shared-ux-file-util": "link:bazel-bin/packages/shared-ux/file/util",
"@kbn/shared-ux-link-redirect-app": "link:bazel-bin/packages/shared-ux/link/redirect_app/impl",
"@kbn/shared-ux-link-redirect-app-mocks": "link:bazel-bin/packages/shared-ux/link/redirect_app/mocks",
"@kbn/shared-ux-link-redirect-app-types": "link:bazel-bin/packages/shared-ux/link/redirect_app/types",
Expand Down
7 changes: 7 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ filegroup(
"//packages/shared-ux/card/no_data/impl:build",
"//packages/shared-ux/card/no_data/mocks:build",
"//packages/shared-ux/card/no_data/types:build",
"//packages/shared-ux/file/image/impl:build",
"//packages/shared-ux/file/image/mocks:build",
"//packages/shared-ux/file/image/types:build",
"//packages/shared-ux/file/util:build",
"//packages/shared-ux/link/redirect_app/impl:build",
"//packages/shared-ux/link/redirect_app/mocks:build",
"//packages/shared-ux/link/redirect_app/types:build",
Expand Down Expand Up @@ -681,6 +685,9 @@ filegroup(
"//packages/shared-ux/button/exit_full_screen/mocks:build_types",
"//packages/shared-ux/card/no_data/impl:build_types",
"//packages/shared-ux/card/no_data/mocks:build_types",
"//packages/shared-ux/file/image/impl:build_types",
"//packages/shared-ux/file/image/mocks:build_types",
"//packages/shared-ux/file/util:build_types",
"//packages/shared-ux/link/redirect_app/impl:build_types",
"//packages/shared-ux/link/redirect_app/mocks:build_types",
"//packages/shared-ux/markdown/impl:build_types",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared-ux/card/no_data/mocks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"emitDeclarationOnly": true,
"outDir": "target_types",
"types": [
"jest",
"node",
"react"
"react",
"jest"
]
},
"include": [
Expand Down
148 changes: 148 additions & 0 deletions packages/shared-ux/file/image/impl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")

PKG_DIRNAME = "impl"
PKG_REQUIRE_NAME = "@kbn/shared-ux-file-image"

SOURCE_FILES = glob(
[
"**/*.ts",
"**/*.tsx",
"**/*.mdx",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

# In this array place runtime dependencies, including other packages and NPM packages
# which must be available for this code to run.
#
# To reference other packages use:
# "//repo/relative/path/to/package"
# eg. "//packages/kbn-utils"
#
# To reference a NPM package use:
# "@npm//name-of-package"
# eg. "@npm//lodash"
RUNTIME_DEPS = [
"@npm//@elastic/eui",
"@npm//react",
"@npm//classnames",
"@npm//@emotion/react",
"@npm//@emotion/css",
"//packages/shared-ux/file/util",
"//packages/kbn-shared-ux-utility",
]

# In this array place dependencies necessary to build the types, which will include the
# :npm_module_types target of other packages and packages from NPM, including @types/*
# packages.
#
# To reference the types for another package use:
# "//repo/relative/path/to/package:npm_module_types"
# eg. "//packages/kbn-utils:npm_module_types"
#
# References to NPM packages work the same as RUNTIME_DEPS
TYPES_DEPS = [
"@npm//@elastic/eui",
"@npm//@types/jest",
"@npm//@types/node",
"@npm//@types/react",
"@npm//@types/classnames",
"//packages/kbn-ambient-ui-types",
"//packages/shared-ux/file/util:npm_module_types",
"//packages/shared-ux/file/image/types:npm_module_types",
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
additional_args = [
"--copy-files",
"--quiet"
],
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)

ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

js_library(
name = "npm_module_types",
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web", ":tsc_types"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)

filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)

pkg_npm(
name = "build_types",
deps = [":npm_module_types"],
visibility = ["//visibility:public"],
)
18 changes: 18 additions & 0 deletions packages/shared-ux/file/image/impl/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
id: sharedUX/Components/FileImage
slug: /shared-ux/components/file-image
title: File image
description: Display images stored in Kibana files.
tags: ['shared-ux', 'component', 'files']
date: 2022-11-22
---

## Description

A light wrapper around <EuiImage /> that introduces some "file-aware" functionality like displaying a [blurhash](https://blurha.sh/) before the final image loads.

## Lazy loading

It is a good practice to leverage the browser-native lazy loading of images. Depending on your use case, make sure that content can be loaded lazily where possible.

For more information see the [loading attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading) for more information.
10 changes: 10 additions & 0 deletions packages/shared-ux/file/image/impl/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { Image as FileImage } from './src/image';
export type { Props as FileImageProps } from './src/image';
7 changes: 7 additions & 0 deletions packages/shared-ux/file/image/impl/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/shared-ux-file-image",
"owner": "@elastic/kibana-global-experience",
"runtimeDeps": [],
"typeDeps": []
}
9 changes: 9 additions & 0 deletions packages/shared-ux/file/image/impl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kbn/shared-ux-file-image",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0",
"types": "./target_types/index.d.ts"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';

import { getImageMetadata } from '../util';
import { getImageMetadata } from '@kbn/shared-ux-file-util';
import { getImageData as getBlob, base64dLogo } from '@kbn/shared-ux-file-image-mocks';
import { Image, Props } from './image';
import { getImageData as getBlob, base64dLogo } from './image.constants.stories';

const defaultArgs: Props = { alt: 'test', src: `data:image/png;base64,${base64dLogo}` };

export default {
title: 'components/Image',
title: 'files/Image',
component: Image,
args: defaultArgs,
decorators: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import React from 'react';
import { useState } from 'react';
import { EuiImage, EuiImageProps } from '@elastic/eui';
import type { FileImageMetadata } from '@kbn/shared-ux-file-image-types';
import { getBlurhashSrc } from '@kbn/shared-ux-file-util';
import classNames from 'classnames';
import { css } from '@emotion/react';
import type { FileImageMetadata } from '../../../common';
import { getBlurhashSrc } from '../util';

export type Props = { meta?: FileImageMetadata } & EuiImageProps;

Expand Down
17 changes: 17 additions & 0 deletions packages/shared-ux/file/image/impl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"types": [
"node",
"jest",
"react",
]
},
"include": [
"**/*.ts",
"**/*.tsx",
]
}
Loading