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

feat: add object-fit module #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@utilitycss/utility",
"version": "1.2.1",
"version": "1.2.2",
"description": "Generator for Utility CSS frameworks",
"author": "Andrea Moretti (@axyz) <[email protected]>",
"repository": "utilitycss/utility",
Expand Down
1 change: 1 addition & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as height } from "./height";
export { default as letterSpacing } from "./letter-spacing";
export { default as lineHeight } from "./line-height";
export { default as listStyle } from "./list-style";
export { default as objectFit } from "./object-fit";
export { default as opacity } from "./opacity";
export { default as outline } from "./outline";
export { default as overflow } from "./overflow";
Expand Down
52 changes: 52 additions & 0 deletions src/modules/object-fit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import applyRules from "../util/applyRules";

import { GetRules, Meta, Module } from "../types";

export type ObjectFitSupportedTypes = {
[key in keyof typeof defaultNames]?: string;
};

export type ObjectFitModuleType = Module<ConfigVariables>;

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ConfigVariables {}

const defaultNames = {
"ob:contain": "ob:contain",
"ob:cover": "ob:cover",
"ob:fill": "ob:fill",
"ob:none": "ob:none",
"ob:scaleDown": "ob:scaleDown",
};

const getRules: GetRules<ConfigVariables> = (names) => ({
"ob:contain": {
name: names["ob:contain"],
key: "object-fit",
value: "contain",
},
"ob:cover": { name: names["ob:cover"], key: "object-fit", value: "cover" },
"ob:fill": { name: names["ob:fill"], key: "object-fit", value: "fill" },
"ob:none": { name: names["ob:none"], key: "object-fit", value: "none" },
"ob:scaleDown": {
name: names["ob:scaleDown"],
key: "object-fit",
value: "scale-down",
},
});

const meta: Meta = {
module: "object-fit",
};

const cssModule: ObjectFitModuleType = (config) => (globalConfig) => {
return applyRules({
config,
globalConfig,
defaultNames,
getRules,
meta: Object.assign({}, meta, config && config.meta),
});
};

export default cssModule;