diff --git a/src/PrimerStyleDictionary.ts b/src/PrimerStyleDictionary.ts index 549fd3d67..e7da1956d 100644 --- a/src/PrimerStyleDictionary.ts +++ b/src/PrimerStyleDictionary.ts @@ -30,12 +30,10 @@ import { javascriptEsm, typescriptExportDefinition, jsonNestedPrefixed, - cssThemed, cssCustomMedia, jsonOneDimensional, jsonPostCssFallback, cssMediaQuery, - cssVariables, jsonFigma, } from './formats' @@ -49,11 +47,6 @@ StyleDictionary.registerParser(w3cJsonParser) * Formats * */ -StyleDictionary.registerFormat({ - name: 'css/themed', - formatter: cssThemed, -}) - StyleDictionary.registerFormat({ name: 'css/customMedia', formatter: cssCustomMedia, @@ -64,11 +57,6 @@ StyleDictionary.registerFormat({ formatter: cssMediaQuery, }) -StyleDictionary.registerFormat({ - name: 'css/variables', - formatter: cssVariables, -}) - StyleDictionary.registerFormat({ name: 'javascript/esm', formatter: javascriptEsm, diff --git a/src/formats/cssThemed.ts b/src/formats/cssThemed.ts deleted file mode 100644 index a8a2d39e1..000000000 --- a/src/formats/cssThemed.ts +++ /dev/null @@ -1,35 +0,0 @@ -import StyleDictionary from 'style-dictionary' -import type {FormatterArguments} from 'style-dictionary/types/Format' -import {format} from 'prettier' -import type {LineFormatting} from 'style-dictionary/types/FormatHelpers' -const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers - -/** - * @description Converts `StyleDictionary.dictionary.tokens` to css with prefers dark and light section - * @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts) - * @param arguments.options outputReferences `boolean`, selector `string`, selectorLight `string`, selectorDark `string` - * @returns formatted `string` - */ -export const cssThemed: StyleDictionary.Formatter = ({dictionary, options = {}, file}: FormatterArguments) => { - const {selector, selectorLight, selectorDark} = options - const {outputReferences, descriptions} = options - const formatting: LineFormatting = { - commentStyle: descriptions ? 'long' : 'none', - } - // add file header - const output = [fileHeader({file})] - // add single theme css - output.push(`${selector || ':root'}${selectorLight ? `, ${selectorLight}` : ''}{ - ${formattedVariables({format: 'css', dictionary, outputReferences, formatting})} - }`) - // add auto dark theme css - if (selectorDark) { - output.push(`@media (prefers-color-scheme: dark) { - ${selectorDark} { - ${formattedVariables({format: 'css', dictionary, outputReferences, formatting})} - } - }`) - } - // return prettified - return format(output.join('\n'), {parser: 'css', printWidth: 500}) -} diff --git a/src/formats/cssVariables.test.ts b/src/formats/cssVariables.test.ts index efa9dc4dd..4ac203fb7 100644 --- a/src/formats/cssVariables.test.ts +++ b/src/formats/cssVariables.test.ts @@ -1,4 +1,4 @@ -import {cssVariables} from './cssVariables' +import {cssMediaQuery} from './cssMediaQuery' import {getMockFormatterArguments} from '../test-utilities' import {format} from 'prettier' @@ -14,13 +14,17 @@ describe('Format: css/variables', () => { printWidth: 500, }, ) - expect(cssVariables(input)).toStrictEqual(expectedOutput) + expect(cssMediaQuery(input)).toStrictEqual(expectedOutput) }) it('Formats tokens with custom selectors', () => { const input = getMockFormatterArguments({ - options: { - selector: `[data-color-mode="dark"]`, + file: { + destination: 'test.css', + options: { + showFileHeader: false, + selector: `[data-color-mode="dark"]`, + }, }, }) const expectedOutput = format( @@ -29,13 +33,17 @@ describe('Format: css/variables', () => { }`, {parser: 'css', printWidth: 500}, ) - expect(cssVariables(input)).toStrictEqual(expectedOutput) + expect(cssMediaQuery(input)).toStrictEqual(expectedOutput) }) it('Formats tokens with only options.selector', () => { const input = getMockFormatterArguments({ - options: { - selector: `[data-color-mode="dark"]`, + file: { + destination: 'test.css', + options: { + showFileHeader: false, + selector: `[data-color-mode="dark"]`, + }, }, }) const expectedOutput = format( @@ -44,6 +52,6 @@ describe('Format: css/variables', () => { }`, {parser: 'css', printWidth: 500}, ) - expect(cssVariables(input)).toStrictEqual(expectedOutput) + expect(cssMediaQuery(input)).toStrictEqual(expectedOutput) }) }) diff --git a/src/formats/cssVariables.ts b/src/formats/cssVariables.ts deleted file mode 100644 index 7f369f224..000000000 --- a/src/formats/cssVariables.ts +++ /dev/null @@ -1,25 +0,0 @@ -import StyleDictionary from 'style-dictionary' -import type {FormatterArguments} from 'style-dictionary/types/Format' -import type {LineFormatting} from 'style-dictionary/types/FormatHelpers' -const {fileHeader, formattedVariables} = StyleDictionary.formatHelpers - -/** - * @description Converts `StyleDictionary.dictionary.tokens` to csssection - * @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts) - * @param arguments.options outputReferences `boolean`, selector `string` - * @returns formatted `string` - */ -export const cssVariables: StyleDictionary.Formatter = ({dictionary, options = {}, file}: FormatterArguments) => { - const selector = options.selector ? options.selector : `:root` - const {outputReferences, descriptions} = options - const formatting: LineFormatting = { - commentStyle: descriptions ? 'long' : 'none', - } - - return `${fileHeader({file})}${selector} {\n${formattedVariables({ - format: 'css', - dictionary, - outputReferences, - formatting, - })}\n}\n` -} diff --git a/src/formats/index.ts b/src/formats/index.ts index 910632212..1697588a5 100644 --- a/src/formats/index.ts +++ b/src/formats/index.ts @@ -1,7 +1,5 @@ -export {cssThemed} from './cssThemed' export {cssCustomMedia} from './cssCustomMedia' export {cssMediaQuery} from './cssMediaQuery' -export {cssVariables} from './cssVariables' export {jsonFigma} from './jsonFigma' export {javascriptCommonJs} from './javascriptCommonJs' export {javascriptEsm} from './javascriptEsm' diff --git a/src/platforms/css.ts b/src/platforms/css.ts index 7054146e2..659d0ec74 100644 --- a/src/platforms/css.ts +++ b/src/platforms/css.ts @@ -56,7 +56,7 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options) }, { destination: `${outputFile}`, - format: `css/variables`, + format: `css/mediaQuery`, filter: token => isSource(token) && options?.themed !== true, options: { showFileHeader: false,